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.

Calling Sequence

NCDF_VARPUT, Cdfid, Varid, Value



The netCDF ID, returned from a previous call to NCDF_OPEN or NCDF_CREATE.


The netCDF variable ID, returned from a previous call to NCDF_VARDEF or NCDF_VARID, or the name of the variable.


Data values to be written to the netCDF file. If the data type of Value does not match that of the netCDF variable, it is converted to the correct data type before writing. Value must have a dimensionality less than or equal to that of the variable being written.



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 .


An optional vector containing the starting position to write. The default start position is [0, 0, ...].


An optional vector containing the strides, or writing intervals, between written values of the netCDF variable. The default stride vector is that for a contiguous write, [1, 1, ...].


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.

; 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:

check_id = NCDF_DIMID(id,'z')

NCDF_DIMINQ, id, check_id, dim_name, dim_size

HELP, check_id, dim_name, dim_size

IDL prints:

CHECK_ID     LONG            =   2

DIM_NAME     STRING          = 'z'

DIM_SIZE     LONG            =   0

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.

IDL prints::

% 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.

NCDF_CLOSE, id ; Close the netCDF file.

See Also