NCL Home > Documentation > Language

Common error messages in NCL


Subscript out of range, error in subscript #1

Sample code that causes the error:

;---Using bad index subscripting
    x = random_uniform(-100,100,(/10,20,30/))
    print(x(5,20,5))                           ; index '20' is invalid

;---Using bad coordinate variable subscripting
    ntim = 5
    nlat = 10
    nlon = 20
    y    = random_uniform(0,.100,(/ntim,nlat,nlon/))
    time = ispan(1,ntim,1)
    lat  = fspan(-5,5,nlat)
    lon  = fspan(10,30,nlon)
    y!0 = "time"
    y!1 = "lat"
    y!2 = "lon"
    y&time = time
    y&lat  = lat
    y&lon  = lon

    ys = y(:,{-20:-10},{10:20})  ; range {-20:-10} is invalid for "lat" coord var

Cause: There are two possible causes: 1) subscripting an array using an index that is out-of-range of the size of your array, or 2) subscripting an array using coordinate values that are out-of-range of the coordinate variables. Index subscript numbers start at 0 and go from left to right, so subscript "#1" refers to the second dimension from the left.

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)

Sample code that causes the error:

    x = random_uniform(-50,50,(/5,32,64/))   ; x is 3D (5 x 32 x 64)
    y = x(0,:,:,:)                           ; x is subscripted as a 4D array

Cause: Subscripting an array using the wrong dimensionality.

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

Sample code that causes the error:

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

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

Fix: Use the 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"


syntax error: possibly an undefined procedure

Sample code 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 to load another NCL script that defines it.


syntax error: function fspan expects 3 arguments, got 2

Sample code 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

Sample code 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

Sample code that causes the error:

    x = (/2,5,9,3/)      ; x has 4 elements
    y = (/8,7,0,2,3/)    ; y has 5 elements
    x = y                ; error

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

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

    x = (/2,5,9,3/)      ; x has 4 elements
    y = (/8,7,0,2,3/)    ; y has 5 elements
    x := y               ; x now has 5 elements


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

Sample code that causes the error:

    x = random_uniform(-10,10,(/3,2,2/))   ; x is 3 x 2 x 2
    y = random_uniform(-20,20,(/4,5/))     ; y is 4 x 5
    x = y                                  ; error

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

Fix: Use dimsizes and printVarSummary to check your array sizes, and then correct as necessary. You can also use the reassignment operator.

    x = random_uniform(-10,10,(/3,2,2/))   ; x is 3 x 2 x 2
    y = random_uniform(-20,20,(/4,5/))     ; y is 4 x 5
    x := y                                 ; x is now 4 x 5


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

Sample code that causes the error:

    x = (/2,5,9,3/)      ; x has 4 elements
    y = (/8,7,0,2,3/)    ; y has 5 elements
    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 type of missing value could not be converted to type of variable.

Sample code that causes the error:

  x = (/1,2,3,4,5,-999/)    ; x is an array of integers
  x@_FillValue = -999.      ; -999. is a float, which is a "higher" type than an integer

Cause: Setting a missing value attribute (_FillValue) using a value that is a higher type than the variable you are setting it for.

Fix: The value of the _FillValue attribute must be the same (or lower) type as the variable you are attaching it to. You can use one of the conversion functions, like toint, to force a lower type.


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

Sample code that causes the error:

    x = new(1,float)   ; x is assigned a missing value
    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

Sample code that causes the error:

    x = 5
    print(x1)

Cause: Referencing a variable that doesn't exist.

Fix: Double-check the spelling of the variable you are referencing.


Attempt to reference attribute (FillValue) which is undefined

Sample code that causes the error:

    x            = (/2,5,9,3,0/)
    x@_FillValue = -999

    print(x@FillValue)    ; attribute spelled incorrectly

Cause: Referencing an attribute that doesn't exist.

Fix: Check and correct the spelling of the attribute you are trying to reference.


There are 1 floats larger than INT_MAX, which has been flagged missing

Sample code that causes the error:

    x = 2^31        ; 2.147484e+09
    i = toint(x)     ; triggers the "larger than INT_MAX" error

Cause: Using "toint" to convert a float or double value that is larger than (2^31-1) to an integer.

Fix: Try using tolong, or use where to do something with these large values before converting them:


  x = (/2^19,2^20,2^30,2^31/)
  i = toint(x)    ; triggers the warning

;---Solution 1: live with it; the last value will be set to the default int missing value
  print(i)      ; last value is -2147483647 (integer missing)

;---Solution 2: use "tolong"
  l = tolong(x)
  print(l)        ; last value is 2147483648, the correct value

;---Solution 3: convert large values to a smaller value, and perhaps set to missing
  x@_FillValue = -999
  x = where(x.ge.(2^31-1),x@_FillValue,x)
  j = toint(x)
  print(j)  ; This is effectively the same as solution #1, but
            ; no warnings are produced. Last value is -999 and
            ; is a missing value.


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

Sample code that causes the error:

    x   = (/8,1,5/)
    str = str_join(x,",")    ; str_join expects string input

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.

    x   = (/8,1,5/)
    str = str_join("" + x,",")

Tip: one way you can find out what line an NCL script is failing on is to 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.


tofloat: A bad value was passed to (string) tofloat, input strings must contain numeric digits, replacing with missing value

    str = "ab54cd"
    x   = tofloat(str)

Cause: Trying to convert a string that contains non-numeric characters to a numerical value. This is common when reading in ASCII files that contain non-numeric fields.

Fix: Print out the strings you are trying to convert, to verify that they actually have numbers in them. If they don't, then you either have an error in your code, or you'll need to fix these strings to contain only numerical values before converting them.


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

    x    = (/2,9,3/)      ; x has 3 elements
    y    = (/8,7,0,3/)    ; y has 4 elements
    diff = x-y            ; error

Cause: Trying to subtract two arrays of different lengths.

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


Minus: Number of dimensions do not match, can't continue

  x    = (/(/1,2,3,4/),(/5,6,7,8/),(/9,10,11,12/)/)  ; 3 x 4
  y    = (/1,0,2,5/)                                 ; 4 elements
  diff = x - y

Cause: Trying to subtract two arrays of different dimensionality.

Fix: If one array is a subset in size of another, then you can use the conform function to "conform" the smaller array to the size of the larger one.

  x    = (/(/1,2,3,4/),(/5,6,7,8/),(/9,10,11,12/)/)    ; 3 x 4
  y    = (/1,0,2,5/)                                 ; 4 elements
  diff = x - conform(x,y,1)    ; y will be propagated to a 3 x 4 array


_NclBuildArray: each element of a literal array must have the same dimension sizes, at least one item doesn't

This message comes from trying to use a "nested" array of dimension sizes inside something like a new statement.

  xdims = (/10,20,30/)
  x     = random_uniform(-10,10,xdims)
  data  = new((/2,xdims/),float)          ; this will cause the error

The third line of the above code expands to:

  data = new((/2,(/10,20,30/)/),float)    ; this will cause the error
You cannot use "(/2,(/10,20,30/)/)" syntax in a new statement. It must be changed to "(/2,10,20,30/)":

  xdims = (/10,20,30/)
  xrank = dimsizes(xdims)
  x     = random_uniform(-10,10,xdims)

  data_dims     = new(xrank+1,integer)
  data_dims(0)  = 2
  data_dims(1:) = xdims 
  data = new(data_dims,float)

scalar field is constant; no contour lines will appear

Sample code that causes the error:

  x  = new((/50,50/),float)
  x  = 2.    ; Setting the whole array to a single value, 2.0

  wks = gsn_open_wks("x11","contour")

  res = True
  res@cnFillOn = True
  plot = gsn_csm_contour(wks,x,res)

Cause: You are trying to contour a data variable where every element is the same value. A plot will be created, but it will be a blank box with the text "CONSTANT FIELD - VALUE IS 2".

Fix: If you believe that your data variable should not be constant, then you need to double-check either the data that's being read in, or check all of your calculations. The printMinMax procedure is very useful in "debugging" your data to make sure it has the range of values that you expect.

Sometimes having a constant field is correct. We've seen this occasionally when users try to plot the first time step of simulated data. The first time step might be some an "initial condition" where the whole array is initialized to the same value.

If you simply want to skip the drawing of a plot that has a constant field, then use min and max:

  x  = new((/50,50/),float)
  x  = 2.    ; Setting the whole array to a single value, 2.0

  wks = gsn_open_wks("x11","contour")

  res = True
  res@cnFillOn = True

  if(min(x).eq.max(x)) then
   print("Error: you have a constant field. Will not create a contour plot.")
  else
    plot = gsn_csm_contour(wks,x,res)
  end if

If you want the plot to be drawn, but with a color, then use the cnConstFEnableFill resource as suggested:

  x  = new((/50,50/),float)
  x  = 2.    ; Setting the whole array to a single value, 2.0

  wks = gsn_open_wks("x11","contour")

  res = True
  res@cnConstFEnableFill = True   ; enable the whole field to be drawn in a single color
  res@cnFillOn = True
  plot = gsn_csm_contour(wks,x,res)

ContourPlotDraw: Workspace reallocation would exceed maximum size

Cause: This is caused when trying to contour a very large data array.

Fix: There are two possible fixes.

A quick-and-easy one to try is to switch to raster contouring:

  res@cnFillMode = "RasterFill"
  res@cnRasterSmoothingOn = True   ; optional, but may produce better results

A second fix is more involved, and requires that you "bump up" your workspace size. Add the following code right after your "gsn_open_wks" call:

  setvalues NhlGetWorkspaceObjectId() 
    "wsMaximumSize" : 300000000
  end setvalues 

You will likely need to adjust the "300000000" number. Start with something small and slowly increase it until the error message goes away.

You can permanently bump up the workspace size by setting this resource in your ~/.hluresfile:

  *wsMaximumSize : 300000000


_NhlCreateSplineCoordApprox: Attempt to create spline approximation for X axis failed: consider adjusting trXTensionF value

Cause: If you are plotting regional data over a map via one of the gsn_csm_xxxx_map routines, then the error might be caused by the code trying to add a longitude cyclic point. Try setting res@gsnAddCyclic = False.

If you are not plotting regional data over a map, this message can come from trying to plot data that has highly irregularly-spaced X and/or Y axis coordinate values.

Sample code that causes the error: The script below shows the problem and also the fix, which is to subscript the data over a region that is not so irregularly-spaced.

;
; Generate some dummy data with dummy 1D lat/lon coordinate arrays,
; with highly irregular spacing for the latitudes.
;
  lat       = (/-88,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,88/)
  lon       = ispan(-179,179,60)
  nlat      = dimsizes(lat)
  nlon      = dimsizes(lon)
  lat@units = "degrees_north"
  lon@units = "degrees_east"
  x         = generate_2d_array(10, 10, -19.69, 15.82, 0, (/nlat,nlon/))
  x!0       = "lat"
  x!1       = "lon"
  x&lat     = lat
  x&lon     = lon

  wks = gsn_open_wks("x11","spline_error")

  res              = True
  res@cnFillOn     = True
  res@tiMainString = "Contours are in wrong latitude location"  

  plot = gsn_csm_contour_map(wks,x,res)              ; Warning from "_NhlCreateSplineCoordApprox"

  res@tiMainString = "Contours are in correct latitude location"   

  plot = gsn_csm_contour_map(wks,x({-10:10},:),res)  ; Using {-10:10} subscripting for the
                                                        ; latitudes removes the warning.

Argument list too long

Sample code that causes the error:

  diri  = "/some/directory/path/"
  files = systemfunc("ls -1 " + diri + "sgp15swfcldgrid*")

Cause: You are trying to list the contents of a directory that has hundreds of files, and reaching a UNIX limitation on the "ls" command.

Fix: Use one of these two methods:

  files = systemfunc("cd "+diri+" ; echo sgp15swfcldgrid* | xargs ls")

  files = systemfunc("find " + diri + " -name 'sgp15swfcldgrid*' -print | xargs basename")


Unable to load System Resource File

Sample code that causes the error:

This is an error message that can occur when you run any NCL script.

Cause: You either don't have your NCARG_ROOT environment variable set correctly or set at all. NCARG_ROOT needs to be set to the root location of where the NCL software is installed.

Fix: Check the setting of your NCARG_ROOT environment variable and other NCARG_XXXX variables.

On the UNIX command line, type:

    which ncl

If this returns (for example), "/usr/local/ncl/bin", then NCARG_ROOT should be set to /usr/local/ncl. See the section "Set the NCARG_ROOT environment variable" section on the NCL download page for more information.


ContourPlotSetValues: Data values out of range of levels set by EXPLICITLEVELS mode

Sample code that causes the error:

  a = addfile("$NCARG_ROOT/lib/ncarg/data/cdf/uv300.nc","r")
  u = a->U(1,:,:)                         ; read July zonal winds
  printMinMax(u,0)

  wks = gsn_open_wks("x11","contour")

  res             = True
  res@cnLevelSelectionMode = "ExplicitLevels"   ; set explicit contour levels
  res@cnLevels    = (/ 50, 60, 70, 80, 90, 100, 110 /)

  plot = gsn_csm_contour_map(wks,u,res)    

Cause: You've chosen a set of contour levels that fall completely outside the range of your data. In the above case, "u" has a min/max of -15.27 and 41.07, but the levels specified are greater than the maximum value.

Fix: Fix the cnLevels setting so that at least some of the levels overlap with the actual range of the data you are trying to plot. Use the printMinMax procedure to help determine a good range of levels to use.

ContourPlotDraw: data boundary is out of range


ContourPlotDraw: data boundary is out of range

Sample code that causes the error:

This code may not always produce the error, but we've found that some WRF output files do, so we used a sample WRF output file name here.

  f   = addfile("wrfout_d01_2016-03-23_00:00:00.nc","r")
  wks = gsn_open_wks("x11","wrf_domains")

  res             = True
  res@cnFillOn    = True
  res@sfXArray    = f->XLONG(0,:,:)       ; note the 2D lat/lon coordinates                                     
  res@sfYArray    = f->XLAT(0,:,:)

  plot = gsn_csm_contour(wks,f->HGT(0,:,:),res)
Cause: This error seems to occur wen you are trying to create a contour plot of curvilinear data, but not putting the data over a map.

Fix: Try setting:

  res@trGridType = "TriangularMesh"
This setting causes NCL to use a different contouring algorithm.


ARSCAM/ARPRAM ALGORITHM FAILURE

Sample code that causes the error:

None provided. This is an elusive problem that is hard to reproduce.

Cause: This error is usually caused by a precision error in our low-level contouring algorithm. It seems to occur when you have very "twisty" contours in small plot, like in a panel plot. It is more likely happen when you are drawing filled contours using the default "area fill" mode.

Fix: One thing you can try as a work-around is to fill the contours using "raster fill" mode instead:

   res@cnFillMode = "RasterFill"  ; Default is "AreaFill"
In addition, you can smooth the raster contours, making them closer in appearance to area-filled contours:

  res@cnRasterSmoothingOn = True

Unfortunately, if you need contours produced by the "AreaFill" mode, there's no instant fix for this. We found that if you tweak certain things, like the rotation of your plot (mpCenterLonF), the size of the plot (vpWidthF/vpHeightF), or the contour levels themselves, you might be able to get rid of this error message.

Detailed and low-level description of the underlying problem

There's a low-level package called AREAS that accepts as input groups of boundary lines in a plane (for example, contour lines generated by CONPACK/CONPACKT or geopolitical boundaries generated by EZMAP), puts them in a structure called an "area map", and then processes that structure to determine the collection of areas formed by the superimposed groups of lines. One of the routines of AREAS, called ARPRAM, performs a multi-step process to prepare the area map for use during subsequent calls to other routines of AREAS. The algorithm used by ARPRAM is inherently geometric in nature and would be exact if carried out using infinite-precision real arithmetic; unfortunately, it is not exact when carried out using the available limited-precision arithmetic. Practically speaking, what this means is that one of the steps leaves the area map in a state such that, when the next step is attempted, something unexpected happens, something that should not be possible, something that prevents that step, and subsequent steps, from being completed correctly and makes it unsafe to allow other AREAS routines to be called (because they might loop forever or produce completely incorrect results). At the moment, we understand what happens well enough to detect when it happens, to produce an error message (the infamous "ALGORITHM FAILURE"), and to quit trying to process the area map, but not well enough to fix whatever has gone wrong.


ContourPlotInitialize: no valid values in scalar field; ContourPlot not possible

Sample code that causes the error:

  temp = new((/100,100/),float)           ; Data are all missing 
  wks = gsn_open_wks("x11","plot") 
  plot = gsn_csm_contour(wks,temp,False) 

Cause: This error will occur if your data values are all missing, as they are in the above example. You can verify if your data variable is all missing by using the all and ismissing functions together:

 print("Is temp all missing ? " + all(ismissing(temp))) 

Fix: You cannot plot data that is all missing, so the fix is that you need to check if there's something wrong with your code that's causing your data to be all missing. You can do this by inserting printMinMax calls in your code to see where a calculation might be going wrong. Or, if you are simply reading a data variable off a file and trying to plot it directly, then look at your data variable using printVarSummary and printMinMax together to see if there might be any other issues.


ContourPlotInitialize: 0.0 not currently supported as a missing value; expect inaccurate plot

Sample code that causes the error:

;---Generate dummy bullseye data for contour plot
  M    = 29
  ispn = conform_dims((/M,M/),ispan(-M/2,M/2,1)^2,1)
  jspn = conform_dims((/M,M/),ispan(-M/2,M/2,1)^2,0)
  data = sqrt(64*(jspn + ispn)) 

  data(9:19,9:19) = 0.     ; Set a rectangular block of data to
  data@_FillValue = 0.     ; missing, using 0.0 as a _FillValue

  wks = gsn_open_wks("x11","zero_msg_val")
  res              = True
  res@gsnMaximize  = True
  res@cnFillOn     = True
  res@tiMainString = "Missing value = " + data@_FillValue

;---Plot will be incorrect, with a purple uneven square of data in the middle
  plot = gsn_csm_contour(wks,data,res)

Cause: NCL cannot contour data that has a missing value (_FillValue attribute) equal to 0.0.

Fix: Reset the _FillValue from 0.0 to a different value:

  data@_FillValue = 1e20      ; All zero values will be set to 1e20

;---Plot will be correct, with a white square of missing data in the middle
  res@tiMainString = "Missing value = " + data@_FillValue
  plot = gsn_csm_contour(wks,data,res)


NhlCvtStringToEnum: Unable to convert string

Sample code that causes the error:

This code shows three cases that will produce this error:

  a = addfile("$NCARG_ROOT/lib/ncarg/data/cdf/uv300.nc","r")
  u = a->U(1,:,:)

  wks = gsn_open_wks("x11","contour")

  res = True
  res@cnFillOn = True
  res@mpProjection = "Ortographic"        ; Should be "Orthographic"
  res@cnFillPalette  = "Ranbow"             ; Should be "Rainbow"
  res@cnLevelSelectionMode = "Explicit"    ; Should be "ExplicitLevels"
  res@cnLevels = ispan(-12,40,2)

  plot = gsn_csm_contour_map(wks,u,res)    

Cause: This fatal message occurs when you are setting a graphical resource that expects a predefined string value, and you give it something invalid. Here are the errors the above code will produce:

  fatal:NhlCvtStringToEnum: Unable to convert string "Ortographic" to requested type
  warning:Error retrieving resource mpProjection from args - Ignoring Arg

  fatal:CvtStringToCmap:Unable to convert string "Ranbow" to ColorMap
  warning:Error retrieving resource cnFillPalette from args - Ignoring Arg

  fatal:NhlCvtStringToEnum: Unable to convert string "Explicit" to requested type
  warning:Error retrieving resource cnLevelSelectionMode from args - Ignoring Arg

Fix: Check the values you are using for the resource in question. Once you make the suggested fixes the code will work as expected.

  res@mpProjection  = "Orthographic"
  res@cnFillPalette  = "Rainbow"
  res@cnLevelSelectionMode = "ExplicitLevels"


NhlDraw: cannot draw Plot Member

Sample code that causes the error:

  wks = gsn_open_wks("x11","test")

  res         = True
  res@gsnDraw = False
  res@gsnFrame = False

  contour_line = gsn_csm_contour(wks,z1,res)

  res@cnFillOn = True
  contour_fill = gsn_csm_contour(wks,z2,res)

  overlay(contour_fill,contour_line)

  draw(contour_line)    ; contour_line is now an "overlay" plot and can't be drawn individually.
  frame(wks)

  draw(contour_fill)
  frame(wks)

Cause: This error occurs when you try to draw a plot that has been overlaid on another plot.

Fix: If you need to draw "contour_line" by itself, then you will need to do this before the overlay call:

  wks = gsn_open_wks("x11","test")

  res         = True
  res@gsnDraw = False
  res@gsnFrame = False

  contour_line = gsn_csm_contour(wks,z1,res)

  res@cnFillOn = True
  contour_fill = gsn_csm_contour(wks,z2,res)

  draw(contour_line)   ; draw this before you overlay it
  frame(wks)

  overlay(contour_fill,contour_line)

  draw(contour_fill)
  frame(wks)

is_valid_lat_ycoord: Warning: The units attribute of the Y coordinate array is not set to one of the allowable units values


Full error:

    is_valid_lat_ycoord: Warning: The units attribute of 
    the Y coordinate array is not set to one of the allowable 
    units values (i.e. 'degrees_north'). Your latitude labels 
    may not be correct.

    is_valid_lat_xcoord: Warning: The units attribute of 
    the X coordinate array is not set to one of the allowable 
    units values (i.e. 'degrees_east'). Your longitude labels 
    may not be correct.

Sample code that causes the error:

  f = addfile("$NCARG_ROOT/lib/ncarg/data/cdf/Tstorm.cdf","r") 
  t = f->t    ; 64 x 33 x 36
  wks = gsn_open_wks("png","dataonmap")

  res              = True
  res@cnFillOn     = True

  plot = gsn_csm_contour_map(wks,t(0,:,:),res)

Cause:

This warning can occur if you are trying to plot contours, vectors, or streamlines over a map using one of the gsn_csm_xxxx_map functions (gsn_csm_contour_map, gsn_csm_vector_map, etc) and you either have latitude / longitude coordinate arrays that do not have "units" attributes of "degrees_north" and "degrees_east", or else you have not provided any lat /lon information at all.

Fix: the fix below shows how to fix coordinate arrays that don't have the correct units. If this is not the situation with your own data, then visit the "plotting data on a map" examples page for more information about what the problem might be.

  f = addfile("$NCARG_ROOT/lib/ncarg/data/cdf/Tstorm.cdf","r") 
  t = f->t    ; 64 x 33 x 36

  printVarSummary(t&lat)            ; Notice the missing units
  printVarSummary(t&lon)            ; Ditto


  t&lat@units = "degrees_north"     ; Fix the lat/lon units
  t&lon@units = "degrees_east"

  wks = gsn_open_wks("x11","coord_arrays_error")

  res              = True
  res@cnFillOn     = True
  res@gsnAddCyclic = False     ; Turn off the cyclic point

;---Zoom in on plot for a better view of the data
  res@mpMinLatF    = min(t&lat) - 1
  res@mpMaxLatF    = max(t&lat) + 1
  res@mpMinLonF    = min(t&lon) - 1
  res@mpMaxLonF    = max(t&lon) + 1
  plot = gsn_csm_contour_map(wks,t(0,:,:),res)


check_for_y_lat_coord: Warning: Data either does not contain a valid latitude coordinate array or doesn't contain one at all

Full error:

    check_for_y_lat_coord: Warning: Data either does not contain
    a valid latitude coordinate array or doesn't contain one at all.
    A valid latitude coordinate array should have a 'units'
    attribute equal to one of the following values: 

    'degrees_north' 'degrees-north' 'degree_north' 'degrees north'
    'degrees_N' 'Degrees_north' 'degree_N' 'degreeN' 'degreesN' 'deg
    north'

    check_for_lon_coord: Warning: Data either does not contain
    a valid longitude coordinate array or doesn't contain one at all.
    A valid longitude coordinate array should have a 'units'
    attribute equal to one of the following values: 

    'degrees_east' 'degrees-east' 'degree_east' 'degrees east'
    'degrees_E' 'Degrees_east' 'degree_E' 'degreeE' 'degreesE' 'deg
    east'

Below are two possible scenarios that could cause this warning:

Sample code #1 that causes the error:

  f = addfile("$NCARG_ROOT/lib/ncarg/data/cdf/Tstorm.cdf","r") 
  t = f->t    ; 64 x 33 x 36

  wks = gsn_open_wks("x11","coord_arrays_error")

  res              = True
  res@cnFillOn     = True

  plot = gsn_csm_contour_map(wks,t(0,:,:),res)

Sample code #2 that also causes the error:

  f = addfile("wrfout_d01_2008-09-29_00:00:00","r")

  slp = wrf_user_getvar(f,"slp",0)

  wks = gsn_open_wks("x11","curvilinear")

  res               = True
  res@cnFillOn      = True  
  res@gsnAddCyclic  = False    ; Data is regional, turn off cyclic point

  plot = gsn_csm_contour_map(wks,slp,res)

Cause:

This warning can occur if you are trying to plot contours, vectors, or streamlines over a map using one of the gsn_csm_xxxx_map functions (gsn_csm_contour_map, gsn_csm_vector_map, etc) and you either have latitude / longitude coordinate arrays that do not have "units" attributes of "degrees_north" and "degrees_east", or else you have not provided any lat / lon array information at all.

Fix for sample code #1:

The code below shows how to fix the case in which your data has coordinate arrays, but they either don't have any "units" attributes, or the "units" attributes are incorrect. This is where printVarSummary can come in handy to look at your data to see what's missing.

  f = addfile("$NCARG_ROOT/lib/ncarg/data/cdf/Tstorm.cdf","r") 
  t = f->t    ; 64 x 33 x 36

  printVarSummary(t)         ; Confirm "t" has coordinate arrays "lat" and "lon"
  printVarSummary(t&lat)     ; Notice "lat" and "lon" arrays are missing the 
  printVarSummary(t&lon)     ; "units" attribute.

  t&lat@units = "degrees_north"     ; Add the lat/lon units before plotting.
  t&lon@units = "degrees_east"

  wks = gsn_open_wks("x11","coord_arrays_error")

  res              = True
  res@cnFillOn     = True
  res@gsnAddCyclic = False     ; Turn off the cyclic point

;---Zoom in on plot for a better view of the data
  res@mpMinLatF    = min(t&lat) - 1
  res@mpMaxLatF    = max(t&lat) + 1
  res@mpMinLonF    = min(t&lon) - 1
  res@mpMaxLonF    = max(t&lon) + 1
  plot = gsn_csm_contour_map(wks,t(0,:,:),res)

Fix for sample code #2:

The code below shows how to fix the case in which your data does not have coordinate arrays, but is on a curvilinear grid. This means your lat/lon arrays are two-dimensional and cannot be represented as traditional coordinate arrays. In this case, you must read the lat/lon arrays off the file and attach them as special "lat2d" and "lon2d" attributes to the data variable being plotted:

  a = addfile("wrfout_d01_2008-09-29_00:00:00","r")

  slp       = wrf_user_getvar(a,"slp",0)
  slp@lat2d = wrf_user_getvar(a,"XLAT",0)   ; latitude/longitude
  slp@lon2d = wrf_user_getvar(a,"XLONG",0)  ; required for plotting

  wks = gsn_open_wks("x11","curvilinear")

  res               = True
  res@cnFillOn      = True  
  res@gsnAddCyclic  = False

  plot = gsn_csm_contour_map(wks,slp,res)

If neither of these fixes work for you, then visit the "plotting data on a map" examples page for more information about what the problem might be.


gsn_add_cyclic: Warning: The range of your longitude data is not 360.

Full error:

    gsn_add_cyclic: Warning: The range of your longitude data is not 360.
    You may want to set the gsnAddCyclic resource to False to avoid a
    warning message from the spline function.

    warning:_NhlCreateSplineCoordApprox: Attempt to create spline
    approximation for X axis failed: consider adjusting trXTensionF
    value

    warning:IrTransInitialize: error creating spline approximation for
    trXCoordPoints; defaulting to linear

Sample code that causes the error:

  f = addfile("$NCARG_ROOT/lib/ncarg/data/cdf/Tstorm.cdf","r") 
  t = f->t    ; 64 x 33 x 36

  t&lat@units = "degrees_north"     ; Fix the lat/lon units
  t&lon@units = "degrees_east"

  wks = gsn_open_wks("x11","cyclic_problem")

  res              = True
  res@cnFillOn     = True
  res@gsnAddCyclic = False     ; Turn off the cyclic point

;---Zoom in on plot for a better view of the data
  res@mpMinLatF    = min(t&lat) - 1
  res@mpMaxLatF    = max(t&lat) + 1
  res@mpMinLonF    = min(t&lon) - 1
  res@mpMaxLonF    = max(t&lon) + 1
  plot = gsn_csm_contour_map(wks,t(0,:,:),res)

Cause: In some cases, the gsn_csm_xxxxx_map functions will assume your data is global and hence it will try to add an additional longitude point at lon=360 in order to avoid a "seam" in the plot. If your data is not global or the cyclic point has already been added, then you will likely see this error.

Fix: To fix, simply set gsnAddCyclic to False, which tells the plotting function not to add the longitude cyclic point:

  f = addfile("$NCARG_ROOT/lib/ncarg/data/cdf/Tstorm.cdf","r") 
  t = f->t    ; 64 x 33 x 36

  t&lat@units = "degrees_north"    ; Fix the lat/lon units
  t&lon@units = "degrees_east"

  wks = gsn_open_wks("x11","cyclic_problem")

  res              = True
  res@cnFillOn     = True
  res@gsnAddCyclic = False     ; Turn off the cyclic point

;---Zoom in on plot for a better view of the data
  res@mpMinLatF    = min(t&lat) - 1
  res@mpMaxLatF    = max(t&lat) + 1
  res@mpMinLonF    = min(t&lon) - 1
  res@mpMaxLonF    = max(t&lon) + 1
  plot = gsn_csm_contour_map(wks,t(0,:,:),res)


MDRGSF/MDRGOF - ERROR OPENING RANGS/GSHHS CAT FILE

Full error:

   fatal:MapRGDHDrawMapList: MDRGSF/MDRGOF - ERROR OPENING RANGS/GSHHS CAT FILE
   fatal:PlotManagerDraw: error in plot draw
   fatal:_NhlPlotManagerDraw: Draw error

Sample code that causes the error:

  wks = gsn_open_wks("x11","rangs_test")

  mpres                       = True
  mpres@gsnMaximize           = True
  mpres@mpLimitMode           = "LatLon"
  mpres@mpMinLonF             = -15.
  mpres@mpMaxLonF             =  15
  mpres@mpMinLatF             =  40.
  mpres@mpMaxLatF             =  70.
  mpres@mpDataBaseVersion     = "HighRes" 
  mpres@pmTickMarkDisplayMode = "Always"

  map = gsn_csm_map(wks,res)

Cause: You are trying to use the high-resolution map database (res@mpDataBaseVersion = "HighRes"), but you haven't downloaded the necessary map database files.

Fix: you need to download a set of ten files that NCL reads to generate the high-res coastlines. For information on how to get these files, go to the page on high-resolution coastlines.


TransformPostDraw: tfPolyDrawList element 0 is invalid

Sample code that causes the error:

  wks = gsn_open_wks("x11","polydraw_test")

  mpres = True
  mpres@gsnMaximize = True
  mpres@gsnDraw = False
  mpres@gsnFrame = False
  map = gsn_csm_map(wks,mpres)

  gsres = True
  gsres@gsMarkerIndex = 16
  gsres@gsLineColor = "NavyBlue"
  gsres@gsLineThicknessF = 3

  dum = gsn_add_polyline(wks,map,(/0,0/),(/-90,90/),gsres)
  dum = gsn_add_polyline(wks,map,(/0,180/),(/30,30/),gsres)
  dum = gsn_add_polyline(wks,map,(/-180,0/),(/30,30/),gsres)
  dum = gsn_add_polymarker(wks,map,(/-60,-30,30,60/),(/-45,-15,15,45/),gsres)

  draw(map)     ; Only the last "dum" set of primitives will show up,
  frame(wks)    ; which are the markers in this case.

Cause: If you are using one of the gsn_add_polyxxx functions to add primitives to your plot and not using a unique variable name for the return value, you will one of these errors for every call.

Fix: Make sure each of the variables returned by the gsn_add_polyxxx routines is unique:

  . . .
  dum1 = gsn_add_polyline(wks,map,(/0,0/),(/-90,90/),gsres)
  dum2 = gsn_add_polyline(wks,map,(/0,180/),(/30,30/),gsres)
  dum3 = gsn_add_polyline(wks,map,(/-180,0/),(/30,30/),gsres)
  dum4 = gsn_add_polymarker(wks,map,(/-60,-30,30,60/),(/-45,-15,15,45/),gsres)
  . . .


xxYYYYZZZZ is not a valid resource in nnnn at this time

Sample code that causes the warning:

  M    = 29
  ispn = conform_dims((/M,M/),ispan(-M/2,M/2,1)^2,1)
  jspn = conform_dims((/M,M/),ispan(-M/2,M/2,1)^2,0)
  T    = sqrt(64*(jspn + ispn))

  wks = gsn_open_wks("x11","plot")
  res = True
  res@gsnMaximize = True
  res@xyLineColor = "NavyBlue"
  res@cnLineLabelOn = False
  plot = gsn_csm_contour(wks,T,res)

The above script should produce two warnings:

    warning:xyLineColor is not a valid resource in plot_contour at this time
    warning:cnLineLabelOn is not a valid resource in plot_contour at this time

Cause: This warning can be caused by two things:

  1. Misspelling a graphical resource name, for example, "xyLineColour" instead of "xyLineColor".

  2. Setting a resource that is not recognized by the type of plotting function you are calling, for example, setting "xyLineColor" when drawing a contour plot.

Fix: Double-check the spelling of your graphical resources and make sure you are setting resources that are recognized by the plotting function. In the example above, you want to use cnLineColor, and correct "cnLineLabelOn" to be cnLineLabelsOn.

Tip: If you use an editor enhancement while editing your NCL scripts, this will help you know if you are spelling resources correctly as the resource name will be highlighted. See the Editor enhancement examples page for more details.


NclMalloc Failed

Sample code that causes the error:

Say, for example, there is 8 GB of available memory on your system and that you are trying to read two variables off a NetCDF with the following dimensions:

  f = addfile("some_file.nc","r")
  T = f->T     ; ntim x nlat x mlon        ( 1320 x 360 x 720)
  P = f->P     ; ntim x klev x nlat x mlon ( 1320 x 6 x 360 x 720)

The total memory requirement of these two arrays will be:

  T: 1320*360*720       = 342144000 values
                        = 342144000*4  = 1368576000 bytes (~1.37GB)

  P: 1320*6*360*720     = 2052864000 values
                        = 2052864000*4 = 8211456000 bytes (~8.21GB)

Together, these two arrays require 9,580,032,000 bytes (~9.58 GB), which would lead to the error:

    fatal:NclMalloc Failed

Cause: This message likely means the memory requirements of the variable(s) have exceeded the available memory on your system. This can happen if you are trying to read or create very large arrays, or if you have lots of variables.

Fix: You need to reduce to reduce the amount of memory being requested by the NCL script:

  1. Use a "do" loop to only access part of the arrays at a time:
      f = addfile("some_file.nc","r")
      do nt=0,ntim-1
        T = f->T(nt,:,:)
        do kl=0,klev-1
          P = f->P(nt,kl,:,:)
          ...do some operation with T and P...
        end do
      end do
    
  2. Reduce the spatial dimensions (if possible). This could be useful if you are plotting T and P, plotting every other value may not make that much of a visual difference:

      T = f->T(:,::2,::2)    
      P = f->T(:,:,::2,::2)  
    

  3. If you don't have big arrays, but you have lots of variables in your script, then use delete to remove variables you no longer need:

       f = addfile("some_file.nc","r")
       T      = f->T
       P      = f->P
       QVAPOR = f->QVAPOR
       PH     = f->PH
       T      = T + 300.
       P      = P + f->PB
       QVAPOR = QVAPOR > 0.000
       PH     = ( PH + f->PHB ) / 9.81
    
       z      = wrf_user_unstagger(PH,PH@stagger)
       tk     = wrf_tk( P , T )    ; calculate TK                                                     
       delete([/PH,T/])
    
       slp    = wrf_slp( z, tk, P, QVAPOR )
       delete([/z,tk,P,QVAPOR/])
    

    Tip: Note that several delete commands are used, rather than one big one at the end. This is so you can free up memory as you go, in case new calculations cause you to exceed your machine's memory limit.