[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Which like command for IDL?



Richard G. French (rfrench@wellesley.edu) writes:

> That does the job for a routine you've already compiled, but what if you 
> want to find out BEFORE you compile it which display.pro you would end
> up running? 

Can't be done. Heisenberg uncertainty principle applies.
You can't possibly know WHICH routine you are using until
the wave function collapses. Or, was that an electron? Humm.
Can't remember ... :-(

> Or even better (JD can probably do this with a recursive
> one-line routine), how about a procedure that goes through your full
> path and finds all of the duplicate filenames? 

I'm shocked that you think JD can write better recursive
functions than me. But I'm busy. I'll leave it to him. :-)

> I am sure that I have about six different routines
> called CIRCLE.PRO in libraries that I have gotten from people, and
> having
> a routine that figured this out in advance would be a nice thing.

How about this WHICH program. *Very* quick and dirty.
I'll leave it to others to make perfect. (I can already
think of a couple of ways it can be greatly improved.) 
But this finds the *first* program with the given name 
of all the names I tested it on. Of course, it can 
only find library routines. :-)

   IDL> Which, "arrow"
      D:\RSI\IDL54\lib\arrow.pro

   IDL> Which, "congrid", /Func
      D:\RSI\IDL54\lib\congrid.pro


Cheers,

David

-- 
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155

******************************************************************
PRO WHICH, routineName, Funct=funct

Catch, theError
IF theError NE 0 THEN BEGIN
   Catch, /Cancel
   answer = Dialog_Message("Can't find: " + StrUpCase(routineName) + $
      '. Is this a function?', /Question)
   IF StrUpCase(answer) EQ 'YES' THEN BEGIN
      Catch, theError
      IF theError NE 0 THEN BEGIN
         Catch, /Cancel
         ok = Dialog_Message("Sorry. Can't find: " + $
            StrUpCase(routineName) + '. Returning')
         RETURN
      ENDIF
      Which, routineName, /Funct
   RETURN
   ENDIF ELSE BEGIN
      ok = Dialog_Message("Sorry. Can't find: " + $
         StrUpCase(routineName) + '. Returning')
      RETURN
   ENDELSE
ENDIF

Resolve_Routine, routineName, Is_Function=Keyword_Set(funct)
Help, /Source, Output=text

array = StrPos(STRUPCASE(text), STRUPCASE(routineName) + "  ", -1)
index = Where(array NE -1, count)
IF count GT 0 THEN Print, text[index[0]] ELSE Print, 'Undetermined'
END
******************************************************************