Table of Contents
Creating and writing to netCDF files requires the mex-file as a backend for SNCTOOLS. The java implementation of netCDF suffers from the drawback that it cannot as of yet enter something called "define mode" more than once. This makes the creation or addition of dimensions, variables, and (most importantly, IMHO) attributes entirely a one-shot deal with java, and after you've left define mode for that first and only time, you will be unable to do so again, meaning that if you screw up an attribute, you'd have to essentially rewrite the file from scratch to correct it. That make a java write-backend unsuitable for SNCTOOLS. That means that if you do not have the mex-file installed, then you are basically done with this tutorial.
Before actually creating a netCDF file, let's figure out what we want to create in the first place. Suppose we have a rectangular time series grid of data. The spatial dimensions of the data are latitude and longitude.
Creating an empty netCDF file is as simple as using the rather
aptly-named nc_create_empty.m m-file as so.
>> nc_create_empty ( 'test.nc' )
>> nc_dump ( 'test.nc' )
netcdf test.nc {
}
Now we're ready to add dimensions and variables.