Add NetCDF schema definitions to NetCDF file
ncwriteschema(filename,schema) creates or adds attributes, dimensions, variable definitions and group structure defined in schema to the file filename.
Use ncwriteschema in combination with ncinfo to create a new NetCDF file based on the schema of an existing file. You can also use ncwriteschema to add variable definitions, attributes, dimensions, or group structure to an existing file.
Note: ncwriteschema does not write variable data. Use ncwrite to write data to the created variables. Created unlimited dimensions will have an initial size of 0 until you write data.
Note: ncwriteschema cannot change the format of an existing file. It cannot redefine existing variables and dimensions in filename. If your schema contains attributes, dimensions, variable definitions, or a group structure that already exist in the file, writeschema issues a warning but continues processing.
Text string specifying the name of a NetCDF file. If filename does not exist, ncwriteschema creates a new file using the netcdf4_classic format, unless the Format field in schema specifies another format.
A structure, or array of structures, representing either a dimension, variable, an entire NetCDF file, or a netcdf4 group. A group or file schema can contain a dimension or variable schema, or both. You can use the output returned by ncinfo as a schema structure. The following table lists the fields in the various types of schema structures. Optional fields are marked with asterisk (*).
Create a classic format file with two dimension definitions.
mySchema.Name = '/'; mySchema.Format = 'classic'; mySchema.Dimensions(1).Name = 'time'; mySchema.Dimensions(1).Length = Inf; mySchema.Dimensions(2).Name = 'rows'; mySchema.Dimensions(2).Length = 10; ncwriteschema('emptyFile.nc', mySchema); ncdisp('emptyFile.nc');
Create a netcdf4_classic format file to store a single variable from an existing file. First use ncinfo to get the schema of the peaks variable from the file. Then use ncwriteschema to create a NetCDF file, defining the peaks variable. Use ncread to get the data associated with the peaks variable and then use ncwrite to write the data to the variable in the new NetCDF file.
myVarSchema = ncinfo('example.nc','peaks'); ncwriteschema('peaksFile.nc',myVarSchema); peaksData = ncread('example.nc','peaks'); ncwrite('peaksFile.nc','peaks',peaksData); ncdisp('peaksFile.nc');