NetCDF / SNCTools tips
This page gives you tips about working with NetCDF files on Windows XP through Matlab. SNCTools is a Matlab API for NetCDF.
Install SNCTools on Windows XP without compiling by hand
Download netcdf binaries and put them in C:\Windows\System32
Download MexNC and add the folder path to Matlab. Rename mexnc.mexw32 to mexnc.mex.
Download SNCTools and add the folder path to Matlab (below MexNC folder path).
You'll find links to all files from the NetCDF project page at Unidata.
When I installed the files, there was a warning that MexNC required netcdf 3.6.2 but the binary wasn't available at the time. Luckily it turns out to work fine with netcdf 3.6.1.
Create (and fill) a NetCDF file
Example:
file = 'test.nc';
DIM = 3;
nc_create_empty(file);
nc_add_dimension(file, 'time', DIM);
Pres.Name = 'pressure';
Pres.Nctype = 'double';
Pres.Dimension = {'time'};
Units.Name = 'units';
Units.Value = 'Pa';
Pres.Attribute = [Units];
nc_addvar(file, Pres);
x = 1:DIM;
nc_varput(file, 'pressure', x);
Import data from a NetCDF file into Matlab
Display the contents of the file (number of records, variable names, types and units)
nc_dump(ncfile);
Read variable values
data = nc_varget(ncfile, variable);
Global attribute
nc_attput (ncfile, nc_global, attribute_name, attribute_value);
Global attributes provide information about the dataset as a whole.