X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 24 Oct 2012 04:05 PM by  anon
IDL source code for built-in procedures
 3 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
24 Oct 2012 04:05 PM
    Is the IDL source code available for the built-in procedures and functions? I want to look at n_params() to see how it works, and it's not in the lib/ folder. I would like to write a similar function that does the same thing for keywords inside a function or procedure.

    Deleted User



    New Member


    Posts:
    New Member


    --
    25 Oct 2012 03:32 PM
    Hi Havok, Any of the IDL core procedures will not be open source. They were written in C and are part of the IDL core. These routines are syntax colored dark blue. Cheers, Fernando Exelis VIS

    Deleted User



    New Member


    Posts:
    New Member


    --
    26 Oct 2012 08:09 AM
    Hi, As Fernando said the source code is not available. But you can write your own solution. After, I'm not sure of the usefulness of such a procedure. Because a keyword is an option and should not be conflicting, you don't really have to test to see how many of those are set. Anyway, I have done some work for you, here is my version of n_params() but for keyword. ;+ ; Get the number of keyword set in a procedure. ; ; :Returns: integer ; ; :Examples: ; PRO procedure_name, param0, KEYWORD1=KEYWORD1, KEYWORD2=KEYWORD2, KEYWORD3=KEYWORD3 ; PRINT, 'PARAM NUMBER: ', n_params() ; PRINT, 'KEYWORD NUMBER: ', vs_n_keywords() ; END ; ; IDL> procedure_name, fltarr(100), /KEYWORD1 ; IDL Console : ; PARAM NUMBER: 1 ; KEYWORD NUMBER: 1 ; ; :Restrictions: ; Keywords have to be written properly: ; KEYWORD1=KEYWORD1 ; not like: ; KEYWORD1=KEYWORD ; ; :Author: ; Vincent SARAGO ; Montreal, QC ; +1 514 779 3031 ; vincent.sarago@gmail.com ; http://vincentsarago.wordpress.com ; ; :History: ; 1.0 - 25 Oct. 2012 (V.S) - Initial Work ; ; :Version: 1.0 ; ;- Function VS_N_KEYWORDS compile_opt idl2, hidden catch, theerror if (theerror ne 0) then begin catch, /cancel ok = dialog_message(!error_state.msg, /error) return, -1 endif ii = 0L ;find routines names and informations res = n_elements(scope_traceback()) ; number of routine calls that have brought idl execution to the current point if res le 2 then return, 0 ;if called in $MAIN$ routine_traceback = (scope_traceback(/structure))[res-2] ;routine we want to analyse is in res-2 position routine_name = routine_traceback.routine is_function = routine_traceback.is_function ;tag if function ;extract keywords names from routine info keywords = (routine_info(routine_name, function = is_function, /PARAMETERS)).kw_args for num = 0L, n_elements(keywords) - 1L do begin if keyword_set((scope_varfetch(keywords[num], level = -1))) then ii++ endfor return, ii End ;{VS_N_KEYWORDS} There are some limitation but this should work. Cheers, Vincent Vincent Sarago, M.Sc. Montréal, QC Tel. +1 (514)-779-3031 Email. vincent.sarago@gmail.com Linkedin. vincentsarago Twit. _VincentS_ Web. http://vincentsarago.wordpress.com

    Deleted User



    New Member


    Posts:
    New Member


    --
    29 Oct 2012 09:20 AM
    Hi, Thanks for the answers. Yeah I know the built-in procedures are closed-source. I was just wondering if there was anyway IDL users could get more detail on some pieces of code, in case we didn't understand how some code was working. Thanks Vincent. I will try out this code and see how it works. I mainly want to use it for setting up default run options. I'm lazy, so instead of writing 6 separate lines of "if not keyword_set() then do this " or stringing them all together in one long conditional , I'd rather write one line that says "if number of keywords set is 0 then do this." Thanks again.
    You are not authorized to post a reply.