X
10914

What is the cause of the error "Variable is undefined: ENVITASK."

When I try to run my batch program that uses an ENVITask in IDL, why do I get the following error?

% Variable is undefined: ENVITASK.

Answer:

When writing ENVI extensions and batch routines it is important to include the following line of code after the PRO statement:

COMPILE_OPT IDL2

The COMPILE_OPT statement allows you to give the IDL compiler information that changes some of the default rules for compiling the function or procedure..

We recommend the use of COMPILE_OPT IDL2 in all new code intended for use in a reusable batch routine in ENVI. 

IDL2 is shorthand way of saying:

   COMPILE_OPT DEFINT32, STRICTARR

where DEFINT32 tells IDL to assume that lexical integer constants default to the 32-bit type rather than the usual default of 16-bit integers while STRICTARR will not allow the use of parentheses to index arrays, reserving their use only for functions.  It is this statement that allows the ENVITask to be interpreted as a function.

 You might note that some of the ENVI example code will exhibit this behavior if copied and pasted into an IDL PRO.  In this case, the COMPILE_OPT IDL2 should be added after the PRO statement.  For example:

PRO ExampleProgram

COMPILE_OPT IDL2

    <my code>

END

Reviewed by PS 11/10/14, KK