NCDF_VARDEF

The NCDF_VARDEF function adds a new variable to an open netCDF file in define mode. If successful, the variable ID is returned. If a new variable cannot be defined, NCDF_VARDEF returns -1.

Calling Sequence

Result = NCDF_VARDEF( Cdfid, Name [, Dim] )

Arguments

Cdfid

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

Name

A scalar string containing the variable name.

Dim

An optional vector containing the dimension IDs corresponding to the variable dimensions. If the ID of the unlimited dimension is included, it must be the rightmost element in the array. If Dim is omitted, the variable is assumed to be a scalar.

Keywords

The following keywords specify the data type for the variable. Only one of these keywords can be used. If no data type keyword is specified, FLOAT is used by default.

BYTE

Set this keyword to indicate that the data is composed of bytes.

CHAR

Set this keyword to indicate that the data is composed of bytes (assumed to be ASCII).

DOUBLE

Set this keyword to indicate that the data is composed of double-precision floating-point numbers.

FLOAT

Set this keyword to indicate that the data is composed of floating-point numbers.

LONG

Set this keyword to indicate that the data is composed of longword integers.

SHORT

Set this keyword to indicate that the data is composed of 2-byte integers.

Example

id = NCDF_CREATE('test.nc', /CLOBBER) ; Create the netCDF file.

NCDF_ATTPUT, id, 'TITLE', 'Incredibly Important Data', /GLOBAL

NCDF_ATTPUT, id, 'GALAXY', 'Milky Way', /GLOBAL

NCDF_ATTPUT, id, 'PLANET', 'Earth', /GLOBAL

xid = NCDF_DIMDEF(id, 'x', 100) ; Define the X dimension.

yid = NCDF_DIMDEF(id, 'y', 200) ; Define the Y dimension.

zid = NCDF_DIMDEF(id, 'z', /UNLIMITED) ; Define the Z dimension.

vid0 = NCDF_VARDEF(id, 'image0', [yid, xid], /FLOAT)

vid1 = NCDF_VARDEF(id, 'image1', [yid, xid], /FLOAT)

Rename image0 to dist_image:

dist_id = NCDF_VARID(id, 'image0') ; Demonstrate usage of NCDF_VARID

NCDF_VARRENAME, id, vid0, 'dist_image'

NCDF_ATTPUT, id, vid, 'TITLE', 'DIST_IMAGE'

NCDF_CONTROL, id, /ENDEF ; Put the file into data mode.

image = CONGRID(DIST(200), 200, 100)

NCDF_VARPUT, id, vid, image

INQ_VID = NCDF_VARINQ(id, 'dist_image')

HELP, INQ_VID, /STRUCTURE

IDL prints:

** Structure <400ec678>, 5 tags, length=32, refs=1:

NAME STRING `dist_image'

DATATYPE STRING `FLOAT'

NDIMS LONG 2

NATTS LONG 1

DIM LONG Array(2)

file_inq = NCDF_INQUIRE(id)

HELP, file_inq, /STRUCTURE

IDL prints:

** Structure <400ebdf8>, 4 tags, length=16, refs=1:

NDIMS LONG 3

NVARS LONG 2

NGATTS LONG 3

RECDIM LONG 2

NCDF_CLOSE, id ; Close the NetCDF file.