NCL Website header
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.


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.

There's a more detailed and low-level description.

NhlCvtStringToEnum: Unable to convert string


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)


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.