NCL > Application examples > Basic examples

ContourPlot example 8

ContourPlot animation of vertical temperature profile

This example can be created using HLU C library calls, HLU FORTRAN library calls, or NCL. It demonstrates how to read data from a netCDF file and create a series of contour plots from the data. The example shows a vertical profile of temperature for longitudes separated by 5 degrees. The names of the example codes that create this plot are cn08c.c, cn08f.f, and cn08n.ncl.

View this animation.


This module discusses how to create the previous plot using HLU function calls and NCL. This module also shows how to read netCDF data from a file and produce a series of contour plots. This example reads a subset of temperature data from a netCDF file, creates a contour plot of the data, and then repeats this process to produce several frames in a sequence of time steps. There is no resource file for this example, as all the resources are set in the source code.

A detailed discussion of how this example works appears in its source code.

Creating the plot using HLU C library calls

The HLU C program that generates this plot is called cn08c.c.

Creating the plot using HLU FORTRAN library calls

The HLU FORTRAN program that generates this plot is called cn08f.f.

Creating the plot using NCL

The NCL script that generates this plot is called cn08n.ncl.

The data

The data for this plot is from a netCDF file called contour.cdf. This example data file contains several geophysical variables including a four-dimensional temperature variable, T. A subset of this variable is read from the netCDF file along with latitude and longitude coordinate variables for each time step.

The data file is located in your NCAR Graphics data directory in a subdirectory called "cdf". You can get the name of the data directory by typing "ncargpath data" at your shell prompt. If you have netCDF installed on your system, then you can change directory to where the netCDF file resides and type "ncdump -h contour.cdf" to view the header information for this data file.

How to run this example

The examples are installed in the following locations:

  • $NCARG_ROOT/lib/ncarg/hluex/contourplot/cn08c.c
  • $NCARG_ROOT/lib/ncarg/hluex/contourplot/cn08f.f
  • $NCARG_ROOT/lib/ncarg/nclex/contourplot/cn08n.ncl
The netCDF data file is installed in the following location:

  • $NCARG_ROOT/lib/ncarg/data/cdf/contour.cdf
You can copy this example and run it by typing "ng4ex cn08c", "ng4ex cn08f", or "ng4ex cn08n". A copy of the source file and resource file will be placed in your current working directory. The source code will be compiled and automatically run for you. You must have the netCDF library installed on your system in order to compile the C or FORTRAN version of this example.

You can view the output NCGM file using the NCAR Graphics ctrans utility. (For example, to view the file generated from cn08n.ncl, type "ctrans cn08n.ncgm".)