Main Content

Import CDF Files Using Low-Level Functions

This example shows how to use low-level functions to read data from a CDF file. The MATLAB® low-level CDF functions correspond to routines in the CDF C API library. To use the MATLAB CDF low-level functions effectively, you must be familiar with the CDF C interface.

Open CDF File

Open the sample CDF File,example.cdf.

cdfid = cdflib.open('example.cdf');

Get Information About File Contents

Usecdflib.inquireto get information about the number of variables in the file, the number of global attributes, and the number of attributes with variable scope.

info = cdflib.inquire(cdfid)
info =struct with fields:编码:“IBMPC_ENCODING”多数:‘ROW_MAJOR’maxRec: 23 numVars: 6 numvAttrs: 1 numgAttrs: 3

Get Information About Variables

Usecdflib.inqurieVarto get information about the individual variables in the file. Variable ID numbers start at zero.

info = cdflib.inquireVar(cdfid,0)
info =struct with fields:name: 'Time' datatype: 'cdf_epoch' numElements: 1 dims: [] recVariance: 1 dimVariance: []
info = cdflib.inquireVar(cdfid,1)
info =struct with fields:name: 'Longitude' datatype: 'cdf_int1' numElements: 1 dims: [2 2] recVariance: 0 dimVariance: [1 0]

Read Variable Data into Workspace

Read the data in a variable into the MATLAB workspace. The first variable contains CDF Epoch time values. The low-level interface returns these asdoublevalues.

data_time = cdflib.getVarRecordData(cdfid,0,0)
data_time = 6.3146e+13

Convert the time value to a date vector.

timeVec = cdflib.epochBreakdown(data_time)
timeVec =7×12001 1 1 0 0 0 0

Read Global Attribute from File

Determine which attributes in the CDF file are global.

info = cdflib.inquireAttr(cdfid,0)
info =struct with fields:name: 'SampleAttribute' scope: 'GLOBAL_SCOPE' maxgEntry: 4 maxEntry: -1

Read the value of the attribute. You must use thecdflib.getAttrgEntryfunction for global attributes.

value = cdflib.getAttrgEntry(cdfid,0,0)
value = 'This is a sample entry.'

Close CDF File

Usecdflib.closeto close the CDF file.

cdflib.close(cdfid);

See Also

|

External Websites