X

Help Articles are product support tips and information straight from the NV5 Geospatial Technical Support team developed to help you use our products to their fullest potential.



3693 Rate this article:
No rating

How to fix the compilation error “Only 8 subscripts allowed” in IDL

Reproduce Case

  • Save the below codes in a single .pro file called test_arg.pro.

PRO test_arg

  print,func_test_arg(1,2,3,4,5,6,7,8,9)

END

FUNCTION func_test_arg,a,b,c,d,e,f,g,h,i

  f=a+b+c+d+e+f+g+h+i

  RETURN, f

END

 

  • Compile it: it returns the below error

IDL> .compile -v 'C:\_BERANGERE\TEST_PG\test_arg.pro'

  print,func_test_arg(1,2,3,4,5,6,7,8,9)

                                   ^

% Only 8 subscripts allowed.

  At: C:\_BERANGERE\TEST_PG\test_arg.pro, Line 2

% 1 Compilation error(s) in module TEST_ARG.

% Compiled module: FUNC_TEST_ARG.

 

Why this error?

This error is due to a misinterpretation by the compiler of line 2 of the test code

func_test_arg(1,2,3,4,5,6,7,8,9)

func_test_arg is interpreted as an array instead of a function name.

The reason of this misinterpretation is the function func_test_arg which is located after the main procedure that is calling it in the .pro file. IDL compiler is working line by line. Thus, the function func_test_arg itself – defined at line 5 of the .pro file - is not yet compiled when the compiler is compiling line 2:

func_test_arg(1,2,3,4,5,6,7,8,9)

is then interpreted as follows

func_test_arg is an array

(1,2,3,4,5,6,7,8,9) are the subscripts to locate a specific value in this 9-dimension array

Knowing that IDL does not support array of more than 8 dimensions, an error is caught by the compiler mentioning the limitation to 8 subscripts, i.e. 8 dimensions.

 

A similar error can even be reproduced at the prompt when working with arrays:

IDL > a=intarr(2,2,2)

IDL > print, array(2,1,1,3,2,3,2,5,5)

It returns

print, array(2,1,3,3,2,3,2,5,5)

                               ^

% Only 8 subscripts allowed.

 

Workarounds/suggestions

 

Different approaches can be considered to prevent such compilation error

 

  1. Option 1:
  • save each function/procedure in a separate .pro file called with the function/procedure name. For example: remove the below lines of code from test_arg.pro and save them in a separate .pro files called func_test_arg.pro.

FUNCTION func_test_arg,a,b,c,d,e,f,g,h,i

              f=a+b+c+d+e+f+g+h+i

              RETURN, f

END

  • add the path of test_arg.pro and func_test_arg.pro to the IDL_PATH: from the IDL workbench select Window > Preferences then IDL > Paths and add the appropriate path in the right part of the dialog window. Select it using the checkbox and click Apply and Close.
  • Then restart IDL and try again to compile your .pro

When done the func_test_arg function will be included on IDL’s search path and will be successfully identified as a function when compiling the line 2 of the test_arg.pro code:

func_test_arg(1,2,3,4,5,6,7,8,9)

 

It should then no longer return a compilation error:

IDL> .compile -v 'C:\_BERANGERE\TEST_PG\test_arg.pro'

% Compiled module: TEST_ARG.

% Compiled module: FUNC_TEST_ARG.

 

 

  1. Option 2: always put the procedures or functions called by other procedures/functions at the top of the .pro files so they will be compiled prior to being called

 

Example:

FUNCTION func_test_arg,a,b,c,d,e,f,g,h,i

               f=a+b+c+d+e+f+g+h+i

               RETURN, f

END

PRO test_arg

              print,func_test_arg(1,2,3,4,5,6,7,8,9)

END

 

Compilation will then succeed

IDL> .compile -v 'C:\_BERANGERE\TEST_PG\test_arg.pro'

% Compiled module: FUNC_TEST_ARG.

% Compiled module: TEST_ARG.

 

 

  1. Option 3: use the COMPILE_OPT IDL2 option:

Example:

PRO test_arg

  COMPILE_OPT IDL2

  print,func_test_arg(1,2,3,4,5,6,7,8,9)

END

FUNCTION func_test_arg,a,b,c,d,e,f,g,h,i

     COMPILE_OPT IDL2

  f=a+b+c+d+e+f+g+h+i

  RETURN, f

END

This compilation option is a combination of the DEFINT32 and STRICTARR options – see link below

https://www.l3harrisgeospatial.com/docs/COMPILE_OPT.html

While compiling, IDL will then only allow square brackets to be used to index arrays. It will not allow parentheses. If IDL encounters parentheses, it will assume that this is being used for a function call.

Note that this last option may require updates to your existing code if you are using parenthesis for subscripting arrays, as IDL may now return errors during execution.

 

Compilation will then succeed:

IDL> .compile -v 'C:\_BERANGERE\TEST_PG\test_arg.pro'

% Compiled module: FUNC_TEST_ARG.

% Compiled module: TEST_ARG.

 

Conclusion/best practices

As a conclusion, Option 1 should be enough to fix this specific error. However, Option 2 and 3 are also best practices when working with IDL to prevent compilation errors.

 

 

----------------------------------------------------------

created by BC on 8/30/2021 - reviewed by BC(US)

 

 

Please login or register to post comments.
Featured

End-of-Life Policy Enforcement for ENVI 5.3 / IDL 8.5 and Earlier Versions

5/6/2024

April 1, 2024 Dear ENVI/IDL Customer,  We are reaching out to notify you of our supported... more »

How to Upgrade licenses to ENVI 6.x / IDL 9.x

12/5/2023

What is the new Upgrade function? Starting with ENVI 6.0 and IDL 9.0, we have implemented an... more »

What to do if the 'License Administrator - License Server' for the Next-Generation License Server does not start?

6/13/2023

Background: With the release of ENVI 5.7 & IDL 8.9 and the corresponding Next-Generation licensing... more »

Next-Generation Licensing FAQ

4/28/2023

  NV5 Geospatial has adopted a new licensing technology for all future releases of our ENVI, IDL... more »

The IDL Virtual Machine

6/6/2013

What is the IDL Virtual Machine? An IDL Virtual Machine is a runtime version of IDL that can... more »