Official websites use .gov
A .gov website belongs to an official government organization in the United States.

Secure .gov websites use HTTPS
A lock ( ) or https:// means you’ve safely connected to the .gov website. Share sensitive information only on official, secure websites.




Matlab® Quick Start Guide

1. Introduction

Common Data Format (CDF) is a conceptual data abstraction for storing, manipulating, and accessing multidimensional datasets. CDF is referred to as a data abstraction because the actual physical format in which datasets are stored is not discussed. Instead, the form of the datasets and the means (interface) by which they may be manipulated are described. MATLAB® is a programming platform designed specifically for engineers and scientists to analyze and design systems and products. The MATLAB® language is matrix-based and allows the most natural expression of computational mathematics. MATLAB® high-level functions make it easy to read CDF files. Low-level functions provide direct access to routines in the CDF C API library. The low-level functions should be used if users require more control over the import operation, such as data subsetting for large datasets, or to export data to a CDF file. To use the MATLAB® CDF low-level functions effectively, the user must be familiar with the CDF C interface. More information about CDF can be found here.

2. Files

MATLAB® supports CDF reading and writing with two groups of modules, cdflib and cdfread/cdfinfo/cdfwrite. The module cdflib enables creating/reading/writing portions of CDF variables, while cdfread/cdfwrite reads/writes whole variables. Each release of MATLAB® is based on a particular version of CDF; for instance MATLAB® version 2018a is based on CDF V3.6.1. While this CDF version includes the newer types: CDF_INT8 and CDF_TIME_TT2000, however, the MATLAB® modules still do not support them. The CDF patch provides modified and expanded capabilities of the original cdfread/cdfinfo/cdfwrite from MATLAB®.

Times in CDF are generally stored in one of three forms: CDF_EPOCH (8-byte floating milliseconds from 0AD), CDF_EPOCH16 (two 8-byte floats of seconds from 0AD and picoseconds of that second), and CDF_TIME_TT2000 (8 byte integer of nanoseconds from 2000 AD). SPDF’s spdfcdfread can handle all time types, and optionally can convert their values to MATLAB®‘s datenum. SPDF’s spdfcdfread also provides cdfepoch and cdftt2000 objects (more accurate but not as efficient as MATLAB®‘s datenum).

If users get error messages reading a CDF file while using MATALB distributed CDF package/module they should try the patch from the CDF home page. The patch includes many user suggested enhancements and features. This patch works only for MATLAB® version R2007a and later.

3. Download and Installation

Windows

  1. Download one of following self-extracting files (likely the 64-bit version) built from MS Visual Studio 2015:

  2. Optionally, download the leap second table. Do this only if you intend to use the previous MATLAB® patch.

  3. Double-click the downloaded file to extract the files included in the patch to a directory. The files will be extracted into c:\MATLAB_cdf390_patch by default.

  4. If you have downloaded the leap second table, then set the environment variable CDF_LEAPSECONDSTABLE to the table.

    set CDF_LEAPSECONDSTABLE=‘<patch_install_dir>\CDFLeapSeconds.txt’

    This table will be used, instead of the hard-coded one embedded in the released library. Not setting the environment variable will result in the use of the table from the library. The step is necessary when the leap second table is different from the one in the library. Need to set the environment variable before running CDF modules under MATLAB®.

  5. Invoke MATLAB® and issue the following command at the MATLAB® prompt:

    addpath ‘<patch_install_dir>’

    For example, if the patch is installed under C:\MATLAB_cdf390_patch, the command should be addpath ‘C:\MATLAB_cdf390_patch’

  6. Use MATLAB® as usual: e.g.,

    spdfcdfinfo();
    data=spdfcdfread(‘test.cdf’);

  7. Check the leap second table being used (relevant only to TT2000 time):

    spdfcdfleapsecondsinfo(‘DUMP’, false)

Mac OS X

  1. Download the following compressed tar files (64-bit mode):

  2. Optionally, download the leap second table. Do this only if you intend to use the previous MATLAB® patch.

  3. Move the MATLAB®-CDF-Patch directory in the downloaded file to the directory you want the patch to be installed under.

  4. Extract the files in the patch using the following command:

    tar zxvf

[The files will be extracted into MATLAB_cdf390_patch-[32|64] directory, depending the tarfile being extracted.]

  1. If you have downloaded the leap second table, then set the environment variable CDF_LEAPSECONDSTABLE to the table:

setenv CDF_LEAPSECONDSTABLE “<patch_install_dir>/CDFLeapSeconds.txt” (for c/tcsh shell)
export CDF_LEAPSECONDSTABLE=“<patch_install_dir>/CDFLeapSeconds.txt” (for bash shell)

This table will be used, instead of the hard-coded one embedded in the released library. Not setting the environment variable will result in the use of the table from the library. The step is necessary when the leap second table is different from the one in the library. Need to set the environment variable before running CDF modules under MATLAB®.

Invoke MATLAB® and issue the following command at the MATLAB® prompt:

addpath ‘<patch_install_dir>’

For example, if the 64-bit patch is installed under /Users/cdf, the command should be

addpath ‘/Users/cdf/MATLAB_CDF390_Patch’

  1. Use MATLAB® as usual: e.g.,

    spdfcdfinfo();
    data=spdfcdfread(‘test.cdf’);

  2. Check the leap second table being used (relevant only to TT2000 time):

    spdfcdfleapsecondsinfo(‘DUMP’, false)

Linux

  1. Download one of the following compressed tar files (likely the 64-bit version):

  2. Optionally, download the leap second table. Do this only if you intend to use the previous MATLAB® patch

  3. Go to the directory where you want the patch to be installed under.

  4. Extract the files in the patch using the following command:

    tar zxvf

[The files will be extracted into MATLAB_cdf390_patch-[32|64] directory, depending the tarfile being extracted.]

  1. If you have downloaded the leap second table, then set the environment variable CDF_LEAPSECONDSTABLE to the table:

setenv CDF_LEAPSECONDSTABLE “<patch_install_dir>/CDFLeapSeconds.txt” (for c/tcsh shell)
export CDF_LEAPSECONDSTABLE=“<patch_install_dir>/CDFLeapSeconds.txt” (for bash shell)

This table will be used, instead of the hard-coded one embedded in the released library. Not setting the environment variable will result in the use of the table from the library. The step is necessary when the leap second table is different from the one in the library. Need to set the environment variable before running CDF modules under MATLAB®.

  1. Invoke MATLAB® and issue the following command at the MATLAB® prompt:

addpath ‘<patch_install_dir>’

For example, if the 64-bit patch is installed under /home/cdf, the command should be

addpath ‘/home/cdf/MATLAB_cdf390_patch’

  1. Use MATLAB® as usual: e.g.,

spdfcdfinfo();
data=spdfcdfread(‘test.cdf’);

  1. Check the leap second table being used (relevant only to TT2000 time):

    spdfcdfleapsecondsinfo(‘DUMP’, false)

4. Help Section

For further information on each module please see the help section. Each module is broken down and includes examples.