The NCDF_VARPUT procedure writes a hyperslab of values to a netCDF variable. The netCDF file must be in data mode to use this procedure.
An optional vector containing the counts to be used in writing Value . Note that counts do not have to match the dimensions of Value . The default count vector is the dimensionality of Value .
Suppose that you wish to create a 100x100 byte (0 & 1) checker board. In this case:
offset_even = [0,0] & offset_odd = [1,1]
;
Create offsets for even and odd rows.
count = [50,50] & stride = [2,2] ; Create count and stride values.
black = BYTARR(50,50) > 1B ; Make the "black" spaces of the checker board.
id = NCDF_CREATE('checker.nc', /CLOBBER)
;
Create the netCDF file.
NCDF_CONTROL, id, /FILL ; Fill the file with BYTE zeros.
xid = NCDF_DIMDEF(id, 'x', 100) ; Define the X dimension.
yid = NCDF_DIMDEF(id, 'y', 100) ; Define the Y dimension.
zid = NCDF_DIMDEF(id, 'yy', /UNLIMITED) ; Define the Z dimension, UNLIMITED.
vid = NCDF_VARDEF(id, 'board', [yid, xid], /BYTE)
;
Define a variable with the name "board".
NCDF_DIMRENAME, id, zid, 'z' ; Rename 'yy' to 'z' as the zid dimension name.
NCDF_CONTROL, id, /ENDEF ; Put the file into data mode.
Use NCDF_DIMID and NCDF_DIMINQ to verify the name and size of the zid dimension:
NCDF_DIMINQ, id, check_id, dim_name, dim_size
HELP, check_id, dim_name, dim_size
Note that the DIM_SIZE is 0 because no records have been written yet for this dimension.
NCDF_VARPUT, id, vid, black, $
COUNT=count, STRIDE=stride, OFFSET=offset_even
NCDF_VARPUT, id, vid, black, $
COUNT=count, STRIDE=stride, OFFSET=offset_odd
NCDF_VARGET, id, vid, output ; Get the full image.
WINDOW, XSIZE=100, YSIZE=100 ; Create a window for displaying the image.
TVSCL, output ; Display the image.
stride = [2,3] ; Make stride larger than possible.
NCDF_VARPUT, id, vid, black, $
COUNT=count, STRIDE=stride, OFFSET=offset_odd
;
As an experiment, attempt to write to an array larger than the one we previously allocated with NCDF_VARDEF.
% NCDF_VARPUT: Requested write is larger than the available data area.
You will need to change the OFFSET/COUNT/STRIDE, or redefine the variable dimensions. You attempted to access 150 elements in a 100 array.