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®.
All SPDF-distributed modules are now renamed with a prefix of ‘SPDF’, e.g., SPDFCDFREAD, SPDFCDFWRITE, etc. Each module still keeps its original functionality and may have a few new enhancements/features.
Extra information is being collected by the SPDFCDFINFO. This new information will make it easier to create new CDF files, based on a template as the ‘MASTER’ CDF to provide the file settings, and variable and attributes specifications. SPDFCDFWRITE is enhanced to use the information for the CDF write.
SPDFCDFREAD is modified to have: ‘CombineRecords’, true as the default, due to its greatly improved performance and smaller returned data size.
A complete set of epoch data handling modules were added. These modules can encode, parse, compute, and break down the epoch data, in CDF_EPOCH, CDF_EPOCH16, and TT2000 format. These modules are:
spdfbreakdownepoch
spdfcomputeepoch
spdfepochtodatenum
spdfbreakdownepoch16
spdfcomputeepoch16
spdfepoch16todatenum
spdfbreakdowntt2000
spdfcomputett2000
spdftt2000todatenum
spdfdatenumtoepoch
spdfparseepoch
spdfencodeepoch
spdfdatenumtoepoch16
spdfparseepoch16
spdfencodeepoch16
spdfdatenumtott2000
spdfparsett2000
spdfencodett2000
spdfcdfleapsecondsinfo
spdfepochunixtime
spdfepoch16unixtime
spdftt2000unixtime
Use “help” for their information.
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:
Download one of following self-extracting files (likely the 64-bit version) built from MS Visual Studio 2015:
Optionally, download the leap second table. Do this only if you intend to use the previous MATLAB® patch.
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.
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®.
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’
Use MATLAB® as usual: e.g.,
spdfcdfinfo();
data=spdfcdfread(‘test.cdf’);
Check the leap second table being used (relevant only to TT2000 time):
spdfcdfleapsecondsinfo(‘DUMP’, false)
Mac OS X:
Download the following compressed tar files (64-bit mode):
Optionally, download the leap second table. Do this only if you intend to use the previous MATLAB patch.
Move the MATLAB®-CDF-Patch directory in the downloaded file to the directory you want the patch to be installed under.
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.]
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’
Use MATLAB® as usual: e.g.,
spdfcdfinfo();
data=spdfcdfread(‘test.cdf’);
Check the leap second table being used (relevant only to TT2000 time):
spdfcdfleapsecondsinfo(‘DUMP’, false)
Linux:
Download one of the following compressed tar files (likely the 64-bit version):
The shared library included has the latest leap second table embedded.
Optionally, download the leap second table. Do this only if you intend to use the previous MATLAB® patch
Go to the directory where you want the patch to be installed under.
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.]
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 /home/cdf, the command should be
addpath ‘/home/cdf/MATLAB_cdf390_patch’
Use MATLAB® as usual: e.g.,
spdfcdfinfo();
data=spdfcdfread(‘test.cdf’);
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.