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

Home » Public Forums » archive » Re: translating an array name to a string
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: translating an array name to a string [message #22151 is a reply to message #22139] Thu, 19 October 2000 00:00 Go to previous messageGo to previous message
John-David T. Smith is currently offline  John-David T. Smith
Messages: 384
Registered: January 2000
Senior Member
Alex Schuster wrote:
>
> David Williams wrote:
>
>> Hi. This is probably a very basic IDL question, so apologies if that's
>> the case. I'm looking for a way to translate the name of an array (e.g.
>> "DATACUBE1") into a string that I can use in titles and/or in feedback
>> at the prompt. I want to make my routines more user-friendly, and I hate
>> forcing a title
>
> Have a look at the OUTPUT keyword to HELP:
>
> IDL> help, movie
> MOVIE BYTE = Array[256, 256, 64]
> IDL> help, movie, output=output
> IDL> print, output
> MOVIE BYTE = Array[256, 256, 64]
> CLU> print, (str_sep( output[0], " "))[0]
> MOVIE


Also try:

print,routine_names(movie,/ARG_NAME)

Don't try looking this one up in the manual. Neither of these
operations are supported. RSI reserves the right to remove or retool
routine_names() AND/OR the output format of help. That's the price you
pay.

By the way, for those of you using routine_names for heavy magic... you
might consider examining the following extra-cautions snippet to export
a variable to the $MAIN$ level:

var_free=0
catch, err
if err ne 0 then begin
;; An undefvar indicates routine_info ran and
;; the variable is free
if !ERROR_STATE.NAME ne 'IDL_M_UNDEFVAR' then begin
catch,/cancel
message,"Can't complete operation... Try obj=sp_sel()"
endif
var_free=1
endif

;; If we need to check if the variable name is available, do so.
if var_free eq 0 then $
rn=call_function('routine_names',var_name,FETCH=1)

if n_elements(rn) ne 0 then begin
catch,/cancel
message,'A variable named '+var_name+' already exists.'
endif

;; Still here... we need to export ourself to the main level
rn=call_function('routine_names',var_name,myvar,store=1)

basically the idea is to wrap routine_names as a string in
call_function, to allow your routine to compile even if RSI yanks or
renames it (it wouldn't compile if you tried to call it directly).
You'll get an error, of course, which will be caught. You have to
discriminate between errors caused by the successful operation of
routine_names(), and those caused by incorrect arguments, changed
keywords (IDL_M_KEYWORD_BAD), or other mutations routine_names() has
undergone (such as vanishing altogether -- IDL_M_UPRO_UNDEF). You
obviously have to have a backup plan too, to tell your users what to do
in case routine_names() has broken. But it's better than your program
not running at all though.

JD

--
J.D. Smith | WORK: (607) 255-6263
Cornell Dept. of Astronomy | (607) 255-5842
304 Space Sciences Bldg. | FAX: (607) 255-5875
Ithaca, NY 14853 |
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Drive detection on win
Next Topic: Re: ShapeFile

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

Current Time: Fri Oct 10 12:02:34 PDT 2025

Total time taken to generate the page: 1.03993 seconds