Writing NetCDF Data as ASCII C Software Documentation

Writing NetCDF Data as ASCII C Software Documentation


Usage

 cdf2asc [-h] [-v variable_of_interest] [-o outputFile] 
       [-i start_index end_index] inputFilePath  

[-h]

This option causes the header data for the given netCDF file to be written to the specified output file stream.

[-v variable_of_interest]

This option allows you to specify the variable you would like to extract. The default is none. The default case should only be used in the presence of the -h option.

[-o outputfile]

This option allows you to enter an optional output filename to which the data you request will be appended. The default is for the output to be written to stdout.

[-i start_index end_index]

This option allows you specify the indeces of the 1st dimension of the variable you wish to extract. At this time you cannot specify indeces for the second dimension of 2-d variables. You may specify a start_index without specifying an end_index.

inputFilePath

The full path to the netCDF file from which you wish to extract ASCII information. This entry MUST be the last command line entry made.

This program writes one and two dimensional netCDF variables to an ASCII file. Currently the program is limited to 2-d data. By specifying certain options you can modify the output. See above for a full description of each option.

Prerequisites

This program CANNOT be compiled without the netCDF library. The source code for the netCDF library can be obtained via anonymous ftp to ftp.unidata.ucar.edu. The necessary files are located in the /pub/netcdf directory.

Additionally, the Makefile provided uses the gcc compiler to compile the program. You may substitute for your local compiler, but if you do, you will need to modify the Makefile to use the flags appropriate to your particular compiler. You may also obtain the gcc compiler, if you do not have it, via anonymous ftp to prep.ai.mit.edu. The gcc compiler is located in the /pub/gnu directory along with a suite of other free goodies.

Please read the Readme included with this release to ensure that the code compiles properly.

Example

Assuming you have met all of the prerequisites, and that you have followed the instructions in the Readme file.
your_machine 1 > make 
your_machine 2 > cdf2asc -h /path_to_data_file/data_file.cdf 
your_machine 3 > cdf2asc -h -v var1 -i 0 0 -o data_file.asc /path_to_data_file/data_file.cdf

Alternatives

The netCDF libraries provide an alternative for viewing netCDF data as ASCII output. The ncdump utility can be used to view the data in an assortment of ways described by the following usage message:

ncdump [-c|-h] [-v ...] [[-b|-f] [c|f]] [-l len] [-n name] [-d n[,n]] file
  [-c]             Coordinate variable data and header information
  [-h]             Header information only, no data
  [-v var1[,...]]  Data for variable(s) ,... only
  [-b [c|f]]       Brief annotations for C or Fortran indices in data
  [-f [c|f]]       Full annotations for C or Fortran indices in data
  [-l len]         Line length maximum in data section (default 80)
  [-n name]        Name for netCDF (default derived from file name)
  [-d n[,n]]       Approximate floating-point values with less precision
  file             File name of input netCDF file

Send your comments to the CIDS Aministrator.

Back to CIDS Page.