Main Content

cdfwrite

(Not recommended) Write data to Common Data Format (CDF) file

cdfwrite is not recommended. Use the cdflib low-level functions instead.

Syntax

cdfwrite(filename,variablelist)
cdfwrite(...,'PadValues',padvals)
cdfwrite(...,'GlobalAttributes',gattrib)
cdfwrite(...,'VariableAttributes',vattrib)
cdfwrite(...,'WriteMode',mode)
cdfwrite(...,'Format',format)

Description

cdfwrite(filename,variablelist) writes out a Common Data Format (CDF) file, to the file name indicated in filename. Specify filename as a character vector or string scalar. The variablelist argument is a cell array of ordered pairs, each of which comprises a CDF variable name (specified as a character vector or string scalar) and the corresponding CDF variable value. To write out multiple records for a variable, put the values in a cell array where each element in the cell array represents a record.

Note

Because cdfwrite creates temporary files, both the destination directory for the file and the current working directory must be writeable.

cdfwrite(...,'PadValues',padvals) writes out pad values for given variable names. padvals is a cell array of ordered pairs, each of which comprises a variable name (specified as a character vector or string scalar) and a corresponding pad value. Pad values are the default values associated with the variable when an out-of-bounds record is accessed. Variable names that appear in padvals must appear in variablelist.

cdfwrite(...,'GlobalAttributes',gattrib) writes the structure gattrib as global metadata for the CDF file. Each field of the structure is the name of a global attribute. The value of each field contains the value of the attribute. To write out multiple values for an attribute, put the values in a cell array where each element in the cell array represents a record.

Note

To specify a global attribute name that is invalid in your MATLAB® application, create a field called 'CDFAttributeRename' in the attribute structure. The value of this field must have a value that is a cell array of ordered pairs. The ordered pair consists of the name of the original attribute, as listed in the GlobalAttributes structure, and the corresponding name of the attribute to be written to the CDF file.

cdfwrite(...,'VariableAttributes',vattrib) writes the structure vattrib as variable metadata for the CDF. Each field of the structure is the name of a variable attribute. The value of each field should be an M-by-2 cell array where M is the number of variables with attributes. The first element in the cell array should be the name of the variable and the second element should be the value of the attribute for that variable.

Note

To specify a variable attribute name that is illegal in MATLAB, create a field called 'CDFAttributeRename' in the attribute structure. The value of this field must have a value that is a cell array of ordered pairs. The ordered pair consists of the name of the original attribute, as listed in the VariableAttributes structure, and the corresponding name of the attribute to be written to the CDF file. If you are specifying a variable attribute of a CDF variable that you are renaming, the name of the variable in the VariableAttributes structure must be the same as the renamed variable.

cdfwrite(...,'WriteMode',mode), where mode is either 'overwrite' or 'append', indicates whether or not the specified variables should be appended to the CDF file if the file already exists. By default, cdfwrite overwrites existing variables and attributes.

cdfwrite(...,'Format',format), where format is either 'multifile' or 'singlefile', indicates whether or not the data is written out as a multifile CDF. In a multifile CDF, each variable is stored in a separate file with the name *.vN, where N is the number of the variable that is written out to the CDF. By default, cdfwrite writes out a single file CDF. When 'WriteMode' is set to 'Append', the 'Format' option is ignored, and the format of the preexisting CDF is used.

Examples

Write out a file 'example.cdf' containing a variable 'Longitude' with the value [0:360].

cdfwrite('example', {'Longitude', 0:360});

Write out a file 'example.cdf' containing variables 'Longitude' and 'Latitude' with the variable 'Latitude' having a pad value of 10 for all out-of-bounds records that are accessed.

cdfwrite('example', {'Longitude', 0:360, 'Latitude', 10:20}, ...
         'PadValues', {'Latitude', 10});

Write out a file 'example.cdf', containing a variable 'Longitude' with the value [0:360], and with a variable attribute of 'validmin' with the value 10.

varAttribStruct.validmin = {'Longitude' [10]};
cdfwrite('example', {'Longitude' 0:360}, 'VariableAttributes', ...
         varAttribStruct);

Limitations

  • CDF files do not support non-ASCII encoded inputs. Variable names, attributes names, variable values, and attribute values must have 7-bit ASCII encoding. Attempting to write non-ASCII encoded inputs results in errors or data with corrupted characters.

Version History

Introduced before R2006a

See Also

|