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.




CDF (V3.9.0 version) Patch for MATLAB®

Mathworks 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 you get error messages reading a CDF file while using MATLAB® distributed CDF package/modules, we strongly encourage you to try the patch from this page. The patch includes many user suggested enhancements and features. This patch works only for MATLAB® version R2007a and later. .

NOTE: Use MATLAB®‘s cdflib.getLibraryVersion function to its CDF’s library version. From this patch, you do this: spdfcdfinfo() to show the library version this patch is based.

Please note: MATLAB®‘s CDFLIB package was developed and is maintained sorely by MATLAB®.

What’s Included in the Patch

Download and Installation Instructions

This latest patch is based on CDF Version 3.9.0 with the module (.m) patched version 3.9.0. You can enter “spdfcdfinfo()” within MATLAB® to view the versions.

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):

    • Mac OS X Intel-based: Patch.
    • Mac OS X Apple Silicon (M*)-based:
      • MATLAB® released version before R2023b: Patch.
      • MATLAB® released version R2023b and later: Patch.
  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.]

  5. 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®.

  6. 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’

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

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

  8. 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. The shared library included has the latest leap second table embedded.

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

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

  5. 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.]

  6. 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®.

  7. 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’

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

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

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

spdfcdfleapsecondsinfo('DUMP', false)  

If you have any questions or encounter problems, please send an email to cdfsupport and we’ll respond as soon as possible.