NCL Home> Application examples> Plot techniques || Data files for some examples

Example pages containing: tips | resources | functions/procedures

Function codes

NCL function codes allow you to add special formatting to any resource that creates a graphical title or label of any sort. Here are some sample function codes and their purposes:

  • "Fn" - change font in midstring
  • "S" or "Sn" - add superscripts
  • "B" or "Bn" - add subscripts
  • "Vn" - change vertical spacing
  • "Hn" - change horizontal spacing

In NCL version 6.1.0 and later, the default function code will be a tilde ('~'). In NCL versions 6.0.0 and earlier, it is a colon (':'), which we always recommended that people change.

If you have an older version of NCL, you can change the function code on the fly as demonstrated in these examples, or in your .hluresfile, which is the preferred method.

These function codes can be used in any resource that creates a text string or label. For example:

fcodes_1.ncl - the most common use of a function code is to change the font in mid string, so you can get a special character or a basic equation in a graphical string. The function code "F", followed by a font table number, is used to change the font.

This example shows how to create a generic string with a font change in the middle.

fcodes_2.ncl Another use of function codes is to generate simple equations. This example shows how to create subscripts and superscripts using the "B" and "S" function codes. Note that these codes can be superceded by a number indicating a level for the sub/superscript. See the function codes description page for more information.
fcodes_3.ncl To add a carriage return to a text string, use the "C" function code. This example shows how to add a carriage return to a main title and labels on the X axis.

The second line of the string will be left-justified with the first line. If you want to center both strings, you will need to add spaces to one or both strings.

text_14.ncl: This example shows how to use text function codes to draw accented characters like the umlaut. This is done using the H and V function codes that allow you to do small vertical and horizontal moves as you are drawing text.

For example, the double dots in the umlaut are drawn by using character "H" from font table 35, and a series of horizontal and vertical moves to put the dots over the desired character.

Note: the default function code is a colon (:), but we recommend changing this to a tilde (~) by creating a .hluresfile in your home directory.

This script was contributed by Mateus da Silva Teixeira from IPMet.