Cdf File Reader

File create in the Common Data Format (CDF), a format used for storing scalar and multidimensional data in a manner independent of the target platform and discipline; used as a scientific data storage and interchange format by various researchers and organizations and often by those in government. Wolfram CDF Player is an application developed by Wolfram Research capable of letting users explore interactive documents in one’s own web browser, views Mathematica examples, reports and files, and interact with applications from the Wolfram Demonstration projects.

  1. Cdf File Reader
  2. Cdf File Reader Pdf
Cdf file reader pdfLast updated Friday 03rd December 1999File

Reading CDF files in Matlab

The CDF (Common Data Format) data file format is often used for distributing and storing STP spacecraft data.

Routines for reading CDF files in IDL are present in the standard CDF distribution. There is no comparable facility for Matlab, however.

I have written several Matlab functions which provide a primitive facility to access data in CDF files. One, cdfinfo lists variables in a CDF file and their properties. Another, cdfread returns data from named variables in the file. Finally, cdf2date,cdf2ep and cdf2time convert CDF Epoch times to Matlab date format, 1950.0 Epoch and [YY DD HH MM SS] format respectively.

Contents

More details

Cdf File Reader

There are several programs, all of which are 'MEX' files - that is, they are compiled C programs that act like Matlab functions. They use v2.6 of the CDF library to retrieve information from CDF files. Once compiled, these programs act like any other M file.

I have produced a distribution which contains SPARC Solaris executables of the programs, so if you use this platform you need not compile the programs. They are statically linked against the CDF library so you don't need to have this either. This distribution also contains source code.

If you do wish to compile the programs, you will need the Matlab v5.2 MEX compiler, which also needs a C compiler. Details vary from platform to platform: consult your Matlab documentation. You will also need the CDF library. There is a source-only distribution which is much smaller than the executable one. Compilation instructions are included in both distributions.

One advantage of compiling the programs yourself is that you can produce versions which are dynamically linked against the CDF library, making the executables much smaller (typically by a factor of about 10). Instructions on how to do this are also included in the distributions.

An example

A typical use of the programs is to extract some magnetic field data from a file and plot it. Here is an example Matlab session:

Version numbers

ProgramVersionDate
cdfread0.4203.11.99
cdfinfo0.302.03.99
cdf2date0.1218.09.99
cdf2ep0.229.04.99
cdf2time0.229.04.99
sizetest0.1026.07.99

Downloading the CDF reader

This software is distributed under the GNU public license. This license imposes significant restrictions on the use of the software, in particular on its distribution. It also limits my legal liabilities. Please read the license carefully before using the software.

Two files are available for download:

Compiled programs for Solaris (updated 03.11.99)
An archive containing executables, for SPARC Solaris 2.6 and Matlab 5.2. These may also work with different versions of Solaris. The executables are statically linked, which makes them rather large. If the CDF library is available on your system, if is better to download the source and re-compile the files with the CDF library dynamically linked. Unzip and untar the archive, then follow instructions in the ReadMe file.
Source programs (updated 03.11.99)
An archive containing source for the MEX files. To compile the programs, you will need a working Matlab installation with the MEX compiler and the CDF library distribution. Unzip and untar the archive, then follow instructions in the ReadMe file.

Mailing list

If you use this software and would like to know when new versions are released (typically every month or two), please email t.horbury@ic.ac.uk and I will put you on an announcement mailing list.

Other links

Tim Horbury home pageLast updated Friday 03rd December 1999 by Tim Horbury.

CDF Overview

Tip: For information on the current CDF version, enter the following at the IDL prompt:

The Common Data Format (CDF) is a file format that facilitates the storage and retrieval of multi-dimensional scientific data. CDF is a product of the National Space Science Data Center (NSSDC).

IDL’s CDF routines all begin with the prefix “CDF_”.

Programming Model

Creating CDF Files

The following table lists the basic IDL commands needed to create a new CDF file:

CDF_CREATE

Call this procedure to begin creating a new file. CDF_CREATE contains a number of keywords which affect the internal format of the new CDF file.

CDF_VARCREATE

Define the variables to be used in the file.

CDF_ATTPUT

Recover my files license key 5 2 1. Optionally, use attributes to describe the data.

CDF_VARPUT

Write the appropriate data to the CDF file.

CDF_CLOSE

Close the file.

Cdf File Reader Pdf

Reading CDF Files

The following table lists the basic commands needed to read data from a CDF file:

CDF_OPENOpen an existing CDF file.
CDF_INQUIRECall this function to find the general information about the contents of the CDF file.
CDF_CONTROLCall this function to obtain further information about the CDF file
CDF_VARINQRetrieve the names, types, sizes, and other information about the variables in the CDF file.
CDF_VARGETRetrieve the variable values.
CDF_ATTINQOptionally, retrieve the names, scope, and other information about the CDF file's attributes.
CDF_ATTGETOptionally, retrieve the attributes.
CDF_CLOSEClose the file.

If the structure of the CDF file is already known, you do not need to call the inquiry routines—only CDF_OPEN, CDF_ATTGET, CDF_VARGET, and CDF_CLOSE are needed.

Type Conversion

Values are converted to the appropriate type before being written to a CDF file. For example, in this code snippet IDL converts the string “12” to a floating-point 12.0 before writing it:

Code Examples

Cdf file reader online

Creating a CDF File

The following example demonstrates the basic procedure for creating a CDF file.

Variables and Attributes

Information in a CDF file consists of attributes (metadata) and collections of data records (variables).

Variables

IDL can create CDF files representing any data that can be stored in a zero- to eight-dimensional array. CDF supports two distinct types of variables, rVariables and zVariables. For reasons of efficiency, CDF uses variances to indicate whether data is unique between records and dimensions. For example, consider a data set of simultaneous surface temperatures at a variety of locations, the IDL code for creating the CDF file is included at the end of this section. A variable representing “GMT time” will vary from record to record, but not dimension to dimension (since all data are taken simultaneously). On the other hand, a variable such as longitude may not vary from record to record, but will vary from dimension to dimension. Record variance is set using the REC_VARY and REC_NOVARY keywords to CDF_VARCREATE, while dimensional variance is set through the DimVary argument to CDF_VARCREATE. In both cases, the default is varying data.

rVariables

rVariables (or regular variables) are multidimensional arrays of values, each having the same dimensions. That is, all rVariables in a CDF must have the same number of dimensions and dimension sizes. In IDL, the rVariable dimension sizes are declared when the CDF file is first created with CDF_CREATE. In the example at the end of this section, all variables except time are rVariables.

zVariables

zVariables (The z doesn’t stand for anything—the CDF people just like the letter z) are multidimensional arrays of values of the same data type. zVariables can have different dimensionality from other zVariables and rVariables. In general, zVariables are much more flexible, and therefore easier to use, than rVariables.

Attributes

Attributes can contain auxiliary information about an entire CDF file (global scope attributes or gAttributes), or about particular CDF variables (variable scope attributes or rAttributes/zAttributes depending on variable type). CDF attributes can be scalar or vector in nature, and of any valid datatype. In the case of vector, or multiple entry, attributes the user must keep track of the entry numbers (in CDF terms these are the gEntry, rEntry, or zEntry numbers depending on attribute type). For example, every rVariable in a CDF file might have an rAttribute named “Date”. A vector zVariable might have a zAttribute named “Location” with values such as [“Melbourne Beach”, “Crowley”,..]. A global attribute “MODS” might be used to keep track of the modification history of a CDF file (see CDF_ATTPUT). Note however, that variables cannot have multiple attributes with the same names. In IDL, CDF attributes are created with CDF_ATTPUT and retrieved with CDF_ATTGET.

Specifying Attributes and Variables

Variables and attributes can be referred to either by name or by their ID numbers in most CDF routines. For example, in the CDF_VARCREATE command shown in the example Type Conversion, the following command would have been equivalent:

Cdf-ms file reader

CDF File Options

File Type

The SINGLE_FILE and MULTI_FILE keywords to CDF_CREATE allow CDFs to be written as either:

  1. all data in a single file, or
  2. a separate file for each variable, plus a master file for global information.

Data Encodings/Decodings

Keywords to CDF_CREATE allow files to be written in a variety of data encoding and decoding options. (For example, the /SUN_ENCODING keyword creates a file in the SUN native encoding scheme). The default encoding/decoding is network (XDR). All CDF encodings and decodings can be written or read on all platforms, but matching the encoding with the architecture used provides the best performance. If you work in a single-platform environment most of the time, select HOST_ENCODING for maximum performance. If you know that the CDF file will be transported to a computer using another architecture, specify the encoding for the target architecture or specify NETWORK_ENCODING (the default). Specifying the target architecture provides maximum performance on that architecture; specifying NETWORK_ENCODING provides maximum flexibility.