How to plot GFS GRIB2 raw data with NCL (NCAR Command Language)

As mentioned in the previous blog post, I used the freely available GFS raw data from NCAR, stored in GRIB2 format, for plotting. NCAR also provides a own plotting language called NCL, which stands for NCAR Command Language. It’s a very useful tool to create both simple and very complex plots of meteorological data. It supports different data formats as e.g. GRIB2 and NetCDF to just mention the most common.
An alternative plotting tool that is commonly used to plot meteorogical data fields is GraDS.

In this post I want to share a simple plotting sample script for plotting a GFS T2m temperature field.
A wide variety of examples can be found at the official NCL page. But unfortunately there are no examples for GFS. So I hope this example can give you a good starting point.

Example for plotting 2m temperature from GFS GRIB2-data

The following example should work under linux distributions and Mac OS X.

  1. Make sure to have NCL installed and running
  2. Download the forecast data from NCEP-servers: e.g. from
  3. Create script file plot_t2m.ncl

    load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
    load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
    ;;; read data from grib file
        fin = addfile(grib_file,"r")    
    ;;; get variables: temperature, longitude, latitude
        t2m = fin->TMP_P0_L103_GLL0(:,:)
        lon = fin->lon_0
        lat = fin->lat_0
    ;;; prepare
        t2m = t2m-273.15    ; degrees
    ;;; create plot (pdf)
        wks = gsn_open_wks("pdf",outfile)                 ; open wk station
        gsn_define_colormap(wks,"BkBlAqGrYeOrReViWh200")  ; load color table
    ;;; Font Style
        res1 = True	                                  ; plots modification on
        res1@txFont = "Helvetica"
        res1@txFontQuality = "High"
    ;;; Title
        res1@tiMainString    = ""   ; add title
        res1@gsnLeftString   = "T2m, SLP"
        res1@gsnRightString  = ""
    ;;; Map
        res1@mpDataBaseVersion = "Ncarg4_1"           ; choose more recent database
        res1@mpDataSetName = "Earth..4"               ; high resolution 
        res1@mpOutlineBoundarySets = "National"       ; National borders
        res1@mpNationalLineColor = "Black"            ; National borders color
    ;;; T2m
        res1@cnFillOn              = True             ; turn on color fill	
        res1@cnLinesOn             = False            ; turn of contour lines
    ;;; color fill tresholds and colors
        res1@cnLevelSelectionMode = "ExplicitLevels"    ; set explicit contour levels
        res1@cnLevels    = (/ -26.,-24.,-22.,-20.,-18.,-16.,-14.,/
                              36.,38.,40./)    ; set levels
        res1@cnFillColors = (/ 10,12,14,15,17,19,22,25,31,35,39,43,48,53,/
                             ; set the colors to be used
    ;;; label bars style
    ;;; if not set standard values are used.
    ;;; so you normally can delete these lines without any problems
        res1@cnInfoLabelOn = False                  ; turn off contour info label
        res1@lbAutoManage          = False          ; control label bar
        res1@pmLabelBarDisplayMode = "Always"       ; turns on label bar
        res1@lbOrientation         = "Vertical"
        res1@pmLabelBarSide        = "Right"
        res1@lbLabelAutoStride =   True
        res1@pmLabelBarWidthF      = 0.1
        res1@pmLabelBarHeightF     = 0.5
        res1@lbLabelFontHeightF    = .010
        res1@lbPerimOn             = False
        res1@lbLabelFont      = "Helvetica"         ; label font
        res1@lbTitleOn        =  True               ; turn on title
        res1@lbTitleString    = "[~S~o~N~C]"        ; title string
        res1@lbTitlePosition  = "Top"               ; title position
        res1@lbTitleFontHeightF= .010               ; make title smaller
        res1@lbTitleDirection = "Across"            ; title direction
    ;;; Map Projection (min and max Lon and Lat)
        res1@gsnAddCyclic          = True           ; data already has cyclic point
                                                    ; this must also be set for any zoom
        res1@mpProjection          = "LambertConformal"
        res1@mpMinLatF            = 30
        res1@mpMaxLatF            = 65 
        res1@mpMinLonF            = -20 
        res1@mpMaxLonF            = 30 
    plot = gsn_csm_contour_map(wks,t2m,res1)     ; create plot

  4. Change the path of the input (“grib_file”) and output file (“outfile”)
  5. run script file with the following command from terminal ncl plot_t2m.ncl

You should get a pdf-file that looks similar to the following:

You like this article? Then you may want to subscribe to our RSS-Feed.

Add a comment


  1. Yann, June 20, 2012:

    Hi, very nice and clear NCL script,
    is “TMP_P0_L103_GLL0(:,:)” really the temperature 2m above ground?
    I don’t see this data in any grib2 file downloaded at the adresse you give.
    Best regards.

  2. larrynewman, June 21, 2012:

    Using ncl_filedump in a shell reveals the following for me:

    float TMP_P0_L103_GLL0 ( lat_0, lon_0 )
    center : US National Weather Service – NCEP (WMC)
    production_status : Operational products
    long_name : Temperature
    units : K
    _FillValue : 1e+20
    grid_type : Latitude/longitude
    parameter_discipline_and_category : Meteorological products, Temperature
    parameter_template_discipline_category_number : ( 0, 0, 0, 0 )
    level_type : Specified height level above ground (m)
    level : 2

    It seems that this variable name does not appear in other grib dump scripts.

  3. Yann, June 21, 2012:

    sorry this is my fault,
    i was using bad grib2 file:

    instead of:

    without the “b”

    Thanks again for your blog!

  4. dooujoa, July 26, 2012:

    First of all, thankyou for your posting..
    when testing your script, I have some questions..

    my error messages are “file format does not appear to be supported and could not open”
    and also,
    “fin” is not defined or variable(TMP_P0_L1_GLL0) is not a variable in the file.

    how and what should i do??

    I am a starter with NCL.
    I hope your answer..

  5. marckus, June 13, 2014:

    Does not work…

    See for more details.
    warning: Entry (224) not found in code table file /usr/local/ncarg/lib/ncarg/grib2_codetables/ncep/4/
    warning: NclGRIB2: codetable file “/usr/local/ncarg/lib/ncarg/grib2_codetables/ncep/4/” not a valid GRIB2 code table.
    warning: Entry (2) not found in code table file /usr/local/ncarg/lib/ncarg/grib2_codetables/ncep/4/4.2.table
    fatal:Number of subscripts do not match number of dimensions of variable, (2) subscripts used, (3) subscripts expected

  6. Dawid, March 7, 2015:

    How to change the input and output file? which give the name of this and how to launch this script? after downloading GRIB forecast what to do next?

  7. NCL Tester, February 7, 2018:


    After exectute this script. One error is displayed ‘fatal:error in statement
    fatal:syntax error: line -1 before or near


    fatal:error in statement

    Can you help me ?


  8. grima, November 30, 2020:

    Thanks for the enlightening example.

    How can you use the above code to plot a line plot of the temperature for a specific country or region? Are there any examples?

    Thank you very much.

Subscribe to Comments (RSS-Feed)

0 Trackbacks/Pingbacks

No Trackbacks yet.