The ncgen utility can do the following with CDL input:
ncgen -o foo.nc foo.cdl
ncgen -c foo.cdl > foo.cor
ncgen -f foo.cdl > foo.f
Programming tip: if a program (e.g. a model) needs to create a netCDF file of specified structure, use a CDL file and ncgen to create the empty netCDF file with no data, then write the data using the appropriate "put_var" calls. For files with lots of metadata, this is easier than writing all the "boiler-plate" code to create the needed dimensions, attributes, and variables manually.
You can use ncdump and ncgen together for some simple netCDF editing:
The Java tool toolsUI available with the netCDF Java package can similarly be used to convert back and forth between netCDF data and editable NcML.
NetCDF-4 note:
The current snapshot release of netCDF-4
includes an ncgen4 tool that handles features of the netCDF-4 data
model in CDL. It can generate binary netCDF files or C, but not
Fortran yet. To build it requires a non-default configure option,
--enable-ncgen4
.