1NCGEN3(1)                      UNIDATA UTILITIES                     NCGEN3(1)
2
3
4

NAME

6       ncgen3  -  From a CDL file generate a netCDF classic or 64 bit classic‐
7       file, a C program, or a Fortran program
8

SYNOPSIS

10       ncgen3 [-b] [-c] [-f] [-k kind_of_file] [-x] [-n] [-o  netcdf_filename]
11              input_file
12

DESCRIPTION

14       ncgen3  generates  either a netCDF file, or C or Fortran source code to
15       create a netCDF file.  The input to ncgen3 is a description of a netCDF
16       file  in  a  small language known as CDL (network Common Data form Lan‐
17       guage), described below.  If no options are specified in  invoking  nc‐
18       gen3,  it merely checks the syntax of the input CDL file, producing er‐
19       ror messages for any violations of CDL syntax.  Other  options  can  be
20       used  to  create the corresponding netCDF file, to generate a C program
21       that uses the netCDF C interface to create the netCDF file, or to  gen‐
22       erate  a Fortran program that uses the netCDF Fortran interface to cre‐
23       ate the same netCDF file.
24
25       ncgen3 may be used with the companion program ncdump  to  perform  some
26       simple  operations on netCDF files.  For example, to rename a dimension
27       in a netCDF file, use ncdump to get a CDL version of the  netCDF  file,
28       edit  the CDL file to change the name of the dimensions, and use ncgen3
29       to generate the corresponding netCDF file from the edited CDL file.
30

OPTIONS

32       -b     Create a (binary) netCDF file.  If the -o option  is  absent,  a
33              default  file  name  will  be  constructed  from the netCDF name
34              (specified after the netcdf keyword in the input)  by  appending
35              the  `.nc'  extension.  If a file already exists with the speci‐
36              fied name, it will be overwritten.
37
38       -c     Generate C source code that will create a netCDF  file  matching
39              the netCDF specification.  The C source code is written to stan‐
40              dard output.
41
42       -f     Generate Fortran source code that  will  create  a  netCDF  file
43              matching  the  netCDF specification.  The Fortran source code is
44              written to standard output.
45
46       -o netcdf_file
47              Name for the binary netCDF file  created.   If  this  option  is
48              specified,  it  implies the "-b" option.  (This option is neces‐
49              sary because netCDF files cannot be written directly to standard
50              output, since standard output is not seekable.)
51
52       -k kind_of_file
53              Using  -k2  or  -k "64-bit offset" specifies that generated file
54              (or program) should use version 2 of format that employs  64-bit
55              file  offsets.  The default is to use version 1 ("classic") for‐
56              mat with 32-bit file offsets, although this limits the  size  of
57              the  netCDF  file, variables, and records to the sizes supported
58              by the classic format.  (NetCDF-4 will support additional  kinds
59              of  netCDF  files,  "netCDF-4"  and  "netCDF-4  classic model".)
60              Note: -v is also accepted to mean the same thing as -k for back‐
61              ward  compatibility,  but  -k  is preferred, to match the corre‐
62              sponding ncdump option.
63
64       -x     Don't initialize data with fill values.  This can speed up  cre‐
65              ation  of large netCDF files greatly, but later attempts to read
66              unwritten data from the generated file will not  be  easily  de‐
67              tectable.
68

EXAMPLES

70       Check the syntax of the CDL file `foo.cdl':
71
72              ncgen3 foo.cdl
73
74       From  the CDL file `foo.cdl', generate an equivalent binary netCDF file
75       named `x.nc':
76
77              ncgen3 -o x.nc foo.cdl
78
79       From the CDL file `foo.cdl', generate a C program containing the netCDF
80       function  invocations  necessary  to create an equivalent binary netCDF
81       file named `x.nc':
82
83              ncgen3 -c -o x.nc foo.cdl
84

USAGE

86   CDL Syntax Summary
87       Below is an example of CDL syntax, describing a netCDF file with sever‐
88       al  named dimensions (lat, lon, and time), variables (Z, t, p, rh, lat,
89       lon, time), variable attributes (units, long_name, valid_range,  _Fill‐
90       Value), and some data.  CDL keywords are in boldface.  (This example is
91       intended to illustrate the syntax; a real CDL file would  have  a  more
92       complete  set  of  attributes so that the data would be more completely
93       self-describing.)
94
95              netcdf foo {  // an example netCDF specification in CDL
96
97              dimensions:
98                   lat = 10, lon = 5, time = unlimited ;
99
100              variables:
101                   long    lat(lat), lon(lon), time(time);
102                   float   Z(time,lat,lon), t(time,lat,lon);
103                   double  p(time,lat,lon);
104                   long    rh(time,lat,lon);
105
106                   // variable attributes
107                   lat:long_name = "latitude";
108                   lat:units = "degrees_north";
109                   lon:long_name = "longitude";
110                   lon:units = "degrees_east";
111                   time:units = "seconds since 1992-1-1 00:00:00";
112                   Z:units = "geopotential meters";
113                   Z:valid_range = 0., 5000.;
114                   p:_FillValue = -9999.;
115                   rh:_FillValue = -1;
116
117              data:
118                   lat   = 0, 10, 20, 30, 40, 50, 60, 70, 80, 90;
119                   lon   = -140, -118, -96, -84, -52;
120              }
121
122       All CDL statements are terminated by a semicolon.   Spaces,  tabs,  and
123       newlines  can  be used freely for readability.  Comments may follow the
124       characters `//' on any line.
125
126       A CDL description consists of three optional parts:  dimensions,  vari‐
127       ables,  and  data,  beginning with the keyword dimensions:, variables:,
128       and data, respectively.  The variable part may contain variable  decla‐
129       rations and attribute assignments.
130
131       A  netCDF  dimension  is used to define the shape of one or more of the
132       multidimensional variables contained in the netCDF file.  A netCDF  di‐
133       mension  has a name and a size.  At most one dimension in a netCDF file
134       can have the unlimited size, which means a variable using  this  dimen‐
135       sion can grow to any length (like a record number in a file).
136
137       A  variable  represents  a multidimensional array of values of the same
138       type.  A variable has a name, a data type, and a shape described by its
139       list  of dimensions.  Each variable may also have associated attributes
140       (see below) as well as data values.  The name, data type, and shape  of
141       a  variable are specified by its declaration in the variable section of
142       a CDL description.  A variable may have the same name as  a  dimension;
143       by  convention  such a variable is one-dimensional and contains coordi‐
144       nates of the dimension it names.  Dimensions need not have  correspond‐
145       ing variables.
146
147       A  netCDF  attribute  contains  information  about a netCDF variable or
148       about the whole netCDF dataset.  Attributes are used  to  specify  such
149       properties  as units, special values, maximum and minimum valid values,
150       scaling factors, offsets, and  parameters.   Attribute  information  is
151       represented by single values or arrays of values.  For example, "units"
152       is an attribute represented by a character array such as "celsius".  An
153       attribute  has  an  associated variable, a name, a data type, a length,
154       and a value.  In contrast to variables that are intended for data,  at‐
155       tributes are intended for metadata (data about data).
156
157       In  CDL,  an  attribute is designated by a variable and attribute name,
158       separated by `:'.  It is possible to assign global attributes not asso‐
159       ciated  with  any variable to the netCDF as a whole by using `:' before
160       the attribute name.  The data type of an attribute in  CDL  is  derived
161       from  the type of the value assigned to it.  The length of an attribute
162       is the number of data values assigned to it, or the number  of  charac‐
163       ters  in  the character string assigned to it.  Multiple values are as‐
164       signed to non-character attributes by separating the values  with  com‐
165       mas.  All values assigned to an attribute must be of the same type.
166
167       The names for CDL dimensions, variables, and attributes must begin with
168       an alphabetic character or `_', and subsequent characters  may  be  al‐
169       phanumeric or `_' or `-'.
170
171       The  optional data section of a CDL specification is where netCDF vari‐
172       ables may be initialized.  The syntax of an initialization is simple: a
173       variable  name, an equals sign, and a comma-delimited list of constants
174       (possibly separated by spaces, tabs and  newlines)  terminated  with  a
175       semicolon.   For  multi-dimensional  arrays,  the last dimension varies
176       fastest.  Thus row-order rather than column order is used for matrices.
177       If  fewer values are supplied than are needed to fill a variable, it is
178       extended with a type-dependent `fill value', which can be overridden by
179       supplying  a value for a distinguished variable attribute named `_Fill‐
180       Value'.  The types of constants need not match the type declared for  a
181       variable; coercions are done to convert integers to floating point, for
182       example.  The constant `_' can be used to designate the fill value  for
183       a variable.
184
185   Primitive Data Types
186              char characters
187              byte 8-bit data
188              short     16-bit signed integers
189              long 32-bit signed integers
190              int  (synonymous with long)
191              float     IEEE single precision floating point (32 bits)
192              real (synonymous with float)
193              double    IEEE double precision floating point (64 bits)
194
195       Except  for the added data-type byte and the lack of unsigned, CDL sup‐
196       ports the same primitive data types as C.  The names for the  primitive
197       data types are reserved words in CDL, so the names of variables, dimen‐
198       sions, and attributes must not be type names.   In  declarations,  type
199       names may be specified in either upper or lower case.
200
201       Bytes  differ  from characters in that they are intended to hold a full
202       eight bits of data, and the zero byte has no special  significance,  as
203       it  does for character data.  ncgen3 converts byte declarations to char
204       declarations in the output C code and to the nonstandard BYTE  declara‐
205       tion in output Fortran code.
206
207       Shorts can hold values between -32768 and 32767.  ncgen3 converts short
208       declarations to short declarations in the output C code and to the non‐
209       standard INTEGER*2 declaration in output Fortran code.
210
211       Longs  can hold values between -2147483648 and 2147483647.  ncgen3 con‐
212       verts long declarations to long declarations in the output C  code  and
213       to  INTEGER  declarations  in output Fortran code.  int and integer are
214       accepted as synonyms for long in CDL declarations.  Now that there  are
215       platforms  with 64-bit representations for C longs, it may be better to
216       use the int synonym to avoid confusion.
217
218       Floats can hold values between about -3.4+38 and 3.4+38.  Their  exter‐
219       nal representation is as 32-bit IEEE normalized single-precision float‐
220       ing point numbers.  ncgen3 converts float declarations to float  decla‐
221       rations in the output C code and to REAL declarations in output Fortran
222       code.  real is accepted as a synonym for float in CDL declarations.
223
224       Doubles can hold values between about -1.7+308 and 1.7+308.  Their  ex‐
225       ternal representation is as 64-bit IEEE standard normalized double-pre‐
226       cision floating point numbers.  ncgen3 converts double declarations  to
227       double declarations in the output C code and to DOUBLE PRECISION decla‐
228       rations in output Fortran code.
229
230   CDL Constants
231       Constants assigned to attributes or variables may be of any of the  ba‐
232       sic netCDF types.  The syntax for constants is similar to C syntax, ex‐
233       cept that type suffixes must be appended to shorts and floats  to  dis‐
234       tinguish them from longs and doubles.
235
236       A  byte constant is represented by a single character or multiple char‐
237       acter escape sequence enclosed in single quotes.  For example,
238               'a'      // ASCII `a'
239               '\0'          // a zero byte
240               '\n'          // ASCII newline character
241               '\33'         // ASCII escape character (33 octal)
242               '\x2b'   // ASCII plus (2b hex)
243               '\377'   // 377 octal = 255 decimal, non-ASCII
244
245       Character constants are enclosed in double quotes.  A  character  array
246       may  be represented as a string enclosed in double quotes.  The usual C
247       string escape conventions are honored.  For example
248              "a"       // ASCII `a'
249              "Two\nlines\n" // a 10-character string with two embedded newlines
250              "a bell:\007"  // a string containing an ASCII bell
251       Note that the netCDF character array "a" would  fit  in  a  one-element
252       variable,  since  no terminating NULL character is assumed.  However, a
253       zero byte in a character array is interpreted as the end of the signif‐
254       icant  characters  by  the  ncdump program, following the C convention.
255       Therefore, a NULL byte should not be embedded in a character string un‐
256       less  at  the  end: use the byte data type instead for byte arrays that
257       contain the zero byte.  NetCDF and CDL have no string  type,  but  only
258       fixed-length character arrays, which may be multi-dimensional.
259
260       short  integer  constants  are  intended for representing 16-bit signed
261       quantities.  The form of a short constant is an integer  constant  with
262       an `s' or `S' appended.  If a short constant begins with `0', it is in‐
263       terpreted as octal, except that if it begins with `0x',  it  is  inter‐
264       preted as a hexadecimal constant.  For example:
265              -2s  // a short -2
266              0123s     // octal
267              0x7ffs  //hexadecimal
268
269       Long  integer  constants  are  intended  for representing 32-bit signed
270       quantities.  The form of a long constant is an  ordinary  integer  con‐
271       stant,  although it is acceptable to append an optional `l' or `L'.  If
272       a long constant begins with `0', it is  interpreted  as  octal,  except
273       that  if  it  begins with `0x', it is interpreted as a hexadecimal con‐
274       stant.  Examples of valid long constants include:
275              -2
276              1234567890L
277              0123      // octal
278              0x7ff          // hexadecimal
279
280       Floating point constants of type float are appropriate for representing
281       floating  point  data with about seven significant digits of precision.
282       The form of a float constant is the same as a C floating point constant
283       with an `f' or `F' appended.  For example the following are all accept‐
284       able float constants:
285              -2.0f
286              3.14159265358979f   // will be truncated to less precision
287              1.f
288
289
290       Floating point constants of type double are appropriate for  represent‐
291       ing floating point data with about sixteen significant digits of preci‐
292       sion.  The form of a double constant is the same as a C floating  point
293       constant.   An  optional  `d'  or `D' may be appended.  For example the
294       following are all acceptable double constants:
295              -2.0
296              3.141592653589793
297              1.0e-20
298              1.d
299
300

BUGS

302       The programs generated by ncgen3 when using the -c or -f  use  initial‐
303       ization statements to store data in variables, and will fail to produce
304       compilable programs if you try to use them for  large  datasets,  since
305       the  resulting  statements may exceed the line length or number of con‐
306       tinuation statements permitted by the compiler.
307
308       The CDL syntax makes it easy to assign what  looks  like  an  array  of
309       variable-length strings to a netCDF variable, but the strings will sim‐
310       ply be concatenated into a single array  of  characters,  since  netCDF
311       cannot  represent  an  array  of  variable-length strings in one netCDF
312       variable.
313
314       NetCDF and CDL do not yet support a type corresponding to a 64-bit  in‐
315       teger.
316
317
318
319Printed: 119-6-20        $Date: 2009/09/24 18:19:10 $                NCGEN3(1)
Impressum