NCL Home > Documentation

Common error messages in NCL


Subscript out of range, error in subscript #0

Example that causes the error:

  x = (/1,2,3,4,5/)
  print(x(5))

Cause: Subscripting an array using an index that is out-of-bounds. Subscript numbers start at 0 and go from left to right, so subscript "#0" is the leftmost dimension.

Fix: Check your subscript indexes to make sure they are in the range of your array size. Use print and printVarSummary.


Number of subscripts on right-hand-side do not match number of dimensions of variable: (4), Subscripts used: (3)

Example that causes the error:

   x = random_uniform(-50,50,(/5,32,64/))   ; x is 3D (5 x 32 x 64)
   y = x(0,:,:,:)

Cause: Subscripting an array using the wrong dimensionality. For example, using four subscripts on a 3D array.

Fix: Check and fix your subscript syntax. Use print and printVarSummary.


Assignment type mismatch, right hand side can't be coerced to type of left hand side

Example that causes the error:

   x = 5
   x = "Now I'm a string"

Cause: Reassigning a variable using a different type or dimensionality.

Fix: Use reassignment operator, or delete the variable first.

   x = 5
   x := "Now I'm a string"

or

   x = 5
   delete(x)
   x = "Now I'm a string"


Number of subscripts on rhs do not match number of dimensions of variable,(1) Subscripts used, (3) Subscripts expected

Example that causes the error:

Cause: Fix: Check for unclosed code blocks and close them.

syntax error: possibly an undefined procedure

Example that causes the error:

   i = 5
   prnt(i)

Cause: Referencing a function or procedure that doesn't exist.

Fix: Check the spelling of function/procedure and whether you need load another NCL script that defines it.


syntax error: function fspan expects 3 arguments, got 2

Example that causes the error:

  x = fspan(0,10)     ; fspan requires 3 arguments

Cause: Calling a function or procedure with the wrong number of arguments.

Fix: Check and correct your function or procedure arguments. Read the documentation for that particular function for help.


syntax error: line -1

Example that causes the error:

  if (x.lt.0) then
     x = 5

Cause: You have an unclosed code block, like a "begin" without an "end", an "if" without an "end if", or a "do" without an "end do".

Fix: Check for unclosed code blocks and close them.


Dimension sizes of left hand side and right hand side of assignment do not match

Example that causes the error:

  x = (/1,2,3,4/)
  y = (/1,2,3,4,5/)
  x = y

Cause: Assigning an array to another array with a different number of elements.

Fix: Check and fix the array sizes on the left and/or right side of the "=".


Number of dimensions on right hand side do not match number of dimension in left hand side

Example that causes the error:

  x = new((/3,2,1/),float)
  y = new((/4,5/),float)
  x = y

Cause: Assigning one array to another when they don't have the same number of dimensions.

Fix: Check your array sizes and correct as necessary. Use dimsizes and printVarSummary.


Dimension size mismatch, dimension (0) of left hand side reference does not have the same size as the right hand side reference after subscripting.

Example that causes the error:

   x = (/1,2,3,4/)
   y = (/1,2,3,4,5/)
   x(0:2) = y(3:4)  ; trying to assign 2 values in y to 3 values in x

Cause: Subsetting an array and trying to assign it a variable or another array subset that has a different number of elements.

Fix: Check and correct your array subscripts.


The result of the conditional expression yields a missing value. NCL can not determine branch, see the ismissing function.

Example that causes the error:

  x = new(1,float)
  if(x.gt.5) then
    print("x > 5")
  end if

Cause: Using a missing value in an "if" statement or some other conditional statement.

Fix: If there's a chance your variable could be missing, then use ismissing to test for missing values.

  x = new(1,float)
  if(.not.ismissing(x).and.x.gt.5) then
    print("x > 5")
  end if


Variable (x1) is undefined

Example that causes the error:

  x = 5
  print(x1)

Cause: Referencing a variable that doesn't exist.

Fix: Check the spelling.


Attempt to reference attribute (FillValue) which is undefined

Example that causes the error:

  x = new(1,float)
  print(x@FillValue)

Cause: Referencing an attribute variable that doesn't exist.

Fix: Check and correct the spelling.


Argument 0 of the current function or procedure was coerced to the appropriate type and thus will not change if the function or procedure modifies its value

Example that causes the error:

  x   = (/1,2,3/)
  str = str_join(x,",")

Cause: Calling a function or procedure with the wrong argument type. This generally happens if the function is expecting a string and you give it a numerical value.

Fix: Convert the argument to a string using the tostring function or concatenating it with an empty string ("") using the (+) operator.

Example that causes the error:

  x   = (/1,2,3/)
  str = str_join(""+x,",")

Note: this type of error usually comes without a line number, making it hard to tell where the error is coming from. If this is the case, then to help locate the error, you can temporarily comment out the "begin" and "end" statements (if any) of the main code, and then run the script with the -x option:

   ncl -x 11.ncl

This will cause every line to be echoed to the screen as it is executed. This should help pinpoint the location of the error.


Minus: Dimension size, for dimension number 0, of operands does not match, can't continue

  x    = (/1,2,3,4/)
  y    = (/1,2,3/)
  diff = x-y

Cause: Trying to subtract two arrays of different sizes.

Fix: Check your arrays to make sure they are the same size. Use printVarSummary to help examine the arrays.