Calling Functions/Procedures Indirectly
The CALL_FUNCTION and CALL_PROCEDURE routines are used to indirectly call functions and procedures whose names are contained in strings. The CALL_METHOD routine can be used to indirectly call an object method whose name is contained in a string. Although not as flexible as the EXECUTE function (see "EXECUTE" (IDL Reference Guide)), the CALL_* routines are much faster, and should be used in preference to EXECUTE whenever possible.
Example
This example code fragment, taken from the routine SVDFIT, calls a function whose name is passed to SVDFIT via a keyword parameter as a string. If the keyword parameter is omitted, the function POLY is called.
; Function declaration. FUNCTION SVDFIT,..., FUNCT = funct ... ; Use default name, POLY, for function if not specified. IF N_ELEMENTS(FUNCT) EQ 0 THEN FUNCT = 'POLY' ; Make a string of the form "a = funct(x,m)", and execute it. Z = EXECUTE('A = '+FUNCT+'(X,M)') ...
The above example is easily made more efficient by replacing the call to EXECUTE with the following line: