NCDF_VARPUT
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.
Examples
Suppose that you wish to create a 100x100 byte (0 & 1) checker board:
; Create offsets for even and odd rows:
offset_even = [0,0] & offset_odd = [1,1]
; Create count and stride values:
count = [50,50] & stride = [2,2]
; Make the "black" spaces of the checker board:
black = BYTARR(50,50, /NOZERO) > 1B
; Create the NetCDF file:
id = NCDF_CREATE('checker.nc', /CLOBBER)
; Fill the file with BYTE zeros:
NCDF_CONTROL, id, /FILL
; Define the X dimension:
xid = NCDF_DIMDEF(id, 'x', 100)
; Define the Y dimension:
yid = NCDF_DIMDEF(id, 'y', 100)
; Define the Z dimension, UNLIMITED:
zid = NCDF_DIMDEF(id, 'yy', /UNLIMITED)
; Define a variable with the name "board":
vid = NCDF_VARDEF(id, 'board', [yid, xid], /BYTE)
; Rename 'yy' to 'z' as the zid dimension name:
NCDF_DIMRENAME, id, zid, 'z'
; Put the file into data mode:
NCDF_CONTROL, id, /ENDEF
; 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
; Get the full image:
NCDF_VARGET, id, vid, output
; Create a window for displaying the image:
WINDOW, XSIZE=100, YSIZE=100
; Display the image:
TVSCL, output
; Make stride larger than possible:
stride = [2,3]
; As an experiment, attempt to write to an array larger than
; the one we previously allocated with NCDF_VARDEF:
NCDF_VARPUT, id, vid, black, $
COUNT=count, STRIDE=stride, OFFSET=offset_odd
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.
Syntax
NCDF_VARPUT, Cdfid, Varid, Value [, COUNT=vector] [, OFFSET=vector] [, STRIDE=vector]
Arguments
Cdfid
The NetCDF ID, returned from a previous call to NCDF_OPEN, NCDF_CREATE, or NCDF_GROUPDEF.
Varid
The NetCDF variable ID, returned from a previous call to NCDF_VARDEF or NCDF_VARID, or the name of the variable.
Value
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.
Keywords
COUNT
An optional vector containing the counts to be used in writing Value. COUNT is a 1-based vector with an element for each dimension of the data to be written. Note that counts do not have to match the dimensions of Value. The default count vector is the dimensionality of Value.
OFFSET
An optional vector containing the starting position to write. The default start position is [0, 0, ...].
STRIDE
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, ...].
Version History
Pre 4.0 |
Introduced |