netCDF  4.2.1.1
CDL Notation for Data Constants

This section describes the CDL notation for constants.

Attributes are initialized in the variables section of a CDL description by providing a list of constants that determines the attribute's length and type (if primitive and not explicitly declared). CDL defines a syntax for constant values that permits distinguishing among different netCDF primitive types. The syntax for CDL constants is similar to C syntax, with type suffixes appended to bytes, shorts, and floats to distinguish them from ints and doubles.

A byte constant is represented by an integer constant with a 'b' (or 'B') appended. In the old netCDF-2 API, byte constants could also be represented using single characters or standard C character escape sequences such as 'a' or '
'. This is still supported for backward compatibility, but deprecated to make the distinction clear between the numeric byte type and the textual char type. Example byte constants include:

     0b      // a zero byte
     -1b     // -1 as an 8-bit byte
     255b    // also -1 as a signed 8-bit byte

Character constants are enclosed in double quotes. A character array may be represented as a string enclosed in double quotes. Multiple CDL strings are concatenated into a single array of characters, permitting long character arrays to appear on multiple lines. To support multiple variable-length textual values, a conventional delimiter such as ',' or blank may be used, but interpretation of any such convention for a delimiter must be implemented in software above the netCDF library layer. The usual escape conventions for C strings are honored. For example:

     "a"            // ASCII 'a'
     "Two\nlines\n" // a 10-character string with two embedded newlines
     "a bell:\007"  // a character array containing an ASCII bell
     "ab","cde"     // the same as "abcde"

The form of a short constant is an integer constant with an 's' or 'S' appended. If a short constant begins with '0', it is interpreted as octal. When it begins with '0x', it is interpreted as a hexadecimal constant. For example:

     2s      // a short 2
     0123s   // octal
     0x7ffs  // hexadecimal

The form of an int constant is an ordinary integer constant. If an int constant begins with '0', it is interpreted as octal. When it begins with '0x', it is interpreted as a hexadecimal constant. Examples of valid int constants include:

     -2
     0123            // octal
     0x7ff           // hexadecimal
     1234567890L     // deprecated, uses old long suffix

The float type is appropriate for representing data with about seven significant digits of precision. The form of a float constant is the same as a C floating-point constant with an 'f' or 'F' appended. A decimal point is required in a CDL float to distinguish it from an integer. For example, the following are all acceptable float constants:

     -2.0f
     3.14159265358979f       // will be truncated to less precision
     1.f
     .1f

The double type is appropriate for representing floating-point data with about 16 significant digits of precision. The form of a double constant is the same as a C floating-point constant. An optional 'd' or 'D' may be appended. A decimal point is required in a CDL double to distinguish it from an integer. For example, the following are all acceptable double constants:

     -2.0
     3.141592653589793
     1.0e-20
     1.d

Unsigned integer constants can be created by appending the character 'U' or 'u' between the constant and any trailing size specifier. Thus one could say 10U, 100us, 100000ul, or 1000000ull, for example.

Constants for the variable-length string type, available as a primitive type in the netCDF-4 enhanced data model are, like character constants, represented using double quotes. This represents a potential ambiguity since a multi-character string may also indicate a dimensioned character value. Disambiguation usually occurs by context, but care should be taken to specify the string type to ensure the proper choice. For example, these two CDL specifications of global attributes have different types:

   :att1 = "abcd", "efg" ;       // a char attribute of length 7
   string :att2 = "abcd", efg" ; // a string attribute of length 2

Opaque constants are represented as sequences of hexadecimal digits preceded by 0X or 0x: 0xaa34ffff, for example. These constants can still be used as integer constants and will be either truncated or extended as necessary.

The ncgen man-page reference has more details about CDL representation of constants of user-defined types.

 All Data Structures Files Functions Variables Typedefs Defines

Generated on Sat Sep 15 2012 12:44:34 for netCDF. NetCDF is a Unidata library.