Introduction

home | toc | about doc | intro | examples | basics | beyond basics | hints and tips | appendix | glossary

The NCAR Command Language (NCL) is a programming language designed specifically for the analysis and visualization of data. NCL can be run in interactive mode, where each line is interpreted as it is entered at your workstation, or it can be run in batch mode as an interpreter of complete scripts. The power and utility of the language are evident in three areas: Each of above areas is discussed below.

File input and output

The file handling capabilities of NCL represent one of its greatest strengths. In addition to being able to read and write the usual binary and ASCII files, NCL can import and export the self-describing and network-transparent data formats netCDF and HDF. NCL can also import the proprietary data formats GRIB and CCM History Tape.

A single NCL function is used to import any of the "supported data formats" (netCDF, HDF, GRIB, or CCM History Tape). This same function can also be used to create HDF and netCDF files. NCL does not create GRIB files, since GRIB files require identifiers for the meteorological center where they were written and for the model used to generate the data. Nor does NCL create CCM History Tape files, since this format will be replaced by netCDF in the future. File types are identified by appropriate file name suffixes. The legal suffixes are: .nc [with .cdf allowed as an alternate], .hdf, .grb, and .ccm. Details on the supported formats are provided in the NCL Reference Manual.

Once a dataset with a supported format is imported, all of its contents are immediately available to NCL. If you are not familiar with such a data format, see "The netCDF User Guide." Once a file has been imported, NCL can print a summary of its contents.

NCL contains a suite of functions for reading and writing ASCII and binary files. Many of these are illustrated in the "Learning NCL by example" chapter of this document. If you already have Fortran or C functions to read or write complicated ASCII or binary files, then it may be easier for you to incorporate those functions into NCL rather than write NCL versions of them using built-in NCL functions. See the section "Incorporating your own Fortran or C code" in the "Going beyond the basics" chapter of this document.

Many examples in this document illustrate NCL's ability to deal simply and effectively with its supported datasets. For a full description of NCL's file I/O capabilities, see the "Files and file variables" section of the NCL Reference Manual.

Data processing

NCL contains many facilities for manipulating data that, taken together, surpass those available in most traditional programming languages. The following headings summarize the features of NCL that make it such a valuable tool for data processing.

Language syntax

NCL has many of the features of programming languages such as Fortran and C. It has variables, data types, and the usual arithmetic, relational, and logical operators. It also has constructs for looping and decision making. All of these language elements are illustrated in the "Learning NCL by example" chapter of this document.

Array processing

Much of NCL's usefulness for data processing derives from its strong array processing capabilities. The arithmetic operators apply to arrays as well as scalars so that arrays can be efficiently added, multiplied, compared, and so forth. NCL also automatically handles missing values.

For details on the powerful array subscripting syntax of NCL, see the section on array subscripting in the "Basics" chapter.

Functions and procedures

NCL has functions that are analogous to Fortran and C functions -- they return a value to the calling script; NCL has procedures that are analogous to Fortran subroutines and to C functions that do not return a value. One very useful feature of functions is that they can return any data type. For example, if you have a function that performs the same operation on every element of a linear array, you can have the function return a linear array as its result. Space for any returned value or values is created automatically by NCL.

NCL has a rich set of built-in functions and procedures, including interpolation and curve-fitting functions, functions for spherical harmonics, and functions for basic statistics. Many of NCL's functions are illustrated in the "Learning NCL by example" chapter of this document. You should also browse the list of built-in functions and procedures and the section on "NCL source code functions and procedures" in the NCL Reference Manual.

Incorporating C, Fortran, and commercial library functions into NCL

Incorporating your own C or Fortran functions or subroutines into NCL can be accomplished by using a "wrapper generator" process. For Fortran this process has been partially automated -- see the section "Incorporating your own Fortran or C code" in the "Going beyond the basics" chapter of this document. For details on the general procedure, see "Extending the NCL function and procedure set" in the NCL Reference Manual.

Missing values

Another useful NCL feature is the capability of defining and using missing values. Variables, or array elements, may be set to a user-specified missing value to indicate missing or invalid data; these missing values are propagated in arithmetic calculations according to well-specified rules.

Graphical display

The third area where NCL excels is graphic display. Publication-quality plots can be produced in black and white, grayscale, or color. These plots can be drawn on a workstation screen, saved as an NCGM file, or saved in PostScript.

Interfaces exist for the rapid display of:

Combinations of these plot types can also be produced. For example, you can easily transform and overlay a contour plot on any of the ten supported world map projections.

Plot details, like the number of contour levels, the contour label fonts to be used, map area masks, and so forth can be controlled by setting values for resources before invoking the plotting interface calls. These resource values can be set using NCL directly, or they can be set in an external ASCII file that NCL can read.

All of the plot types listed, as well as how to set resource values, are illustrated in the "Learning NCL by example" chapter of this document.

The interfaces for rapid plot display do not encompass the full flexibility of the plotting capabilities available in NCL. To find out more about plotting, see the "Going beyond the basics" chapter in this document.


home | toc | about doc | intro | examples | basics | beyond basics | hints and tips | appendix | glossary