Now let's add data to the coordinate variables. The m-file to use here is
nc_varput.m
.
% just example data, could be anything >> latdata = [33:52]'; >> nc_varput ( 'test.nc', 'latitude', latdata ); % just example data, could be anything >> londata = [-90:-61]'; >> nc_varput ( 'test.nc', 'longitude', londata );
Oops, suppose that last longitude value is wrong, that it should be
-60 instead of -61. nc_varput.m
can write to just
just that single value if we specify the indices correctly. Since the
netCDF library expects zero-based indexing, the coordinate of that last
value is 29, not 30. The final argument means that we are writing just
one value.
>> datum = -60; >> nc_varput ( 'test.nc', 'longitude', datum, [29], [1] );
The m-file nc_varput
is pretty picky about being given the correct indexes and will refuse to write data if it thinks you gave it some nonsensical indexes. For example, suppose you had provided too much data in the previous example, i.e.
>> data = [-60;-61]; >> nc_varput ( 'test.nc', 'longitude', data, [29], [1] ); ??? Error using ==> nc_varput nc_varput: total number of input datums was 2, but the count parameter indicated 1 elements.