type.inq.nc: Inquire About a NetCDF Type

View source: R/RNetCDF.R

type.inq.ncR Documentation

Inquire About a NetCDF Type

Description

Inquire about a NetCDF builtin or user-defined data type.

Usage

type.inq.nc(ncfile, type, fields=TRUE)

Arguments

ncfile

Object of class NetCDF which points to the NetCDF dataset or group.

type

ID or name of a NetCDF data type.

fields

Read members of enum types or fields of compound types (default TRUE).

Details

This function obtains information about a NetCDF data type, which could be builtin or user-defined. The items in the return list depend on the class of the NetCDF type.

Value

A list containing the following components:

id

Type ID.

name

Type name.

class

One of the keywords "builtin", "compound", "enum", "opaque" or "vlen".

size

Size in bytes of a single item of the type (or a single element of a "vlen").

basetype

("enum" or "vlen") Name of the NetCDF type of each element.

If fields=TRUE, the return list includes details about members of enum types or fields of compound types:

value

("enum" only) Named vector with numeric values of all members.

offset

("compound" only) Named vector with the offset of each field in bytes from the beginning of the compound type.

subtype

("compound" only) Named vector with the NetCDF type name of each field.

dimsizes

("compound" only) Named list with array dimensions of each field. Dimension lengths are reported in R order (leftmost index varies fastest; opposite to CDL conventions). A NULL length indicates a scalar.

Author(s)

Pavel Michna, Milton Woods

References

https://www.unidata.ucar.edu/software/netcdf/

See Also

grp.inq.nc - get a list of NetCDF types defined in a dataset or group.

type.def.nc - define a new NetCDF type.

Examples

##  Create a new NetCDF4 dataset and define types
file1 <- tempfile("type.inq_", fileext=".nc")
nc <- create.nc(file1, format="netcdf4")

# Define a type of each class:
type.def.nc(nc, "blob", "opaque", size=128)
type.def.nc(nc, "vector", "vlen", basetype="NC_FLOAT")

type.def.nc(nc, "factor", "enum", basetype="NC_INT",
            names=c("peanut butter", "jelly"),
            values=c(101, 102))

type.def.nc(nc, "struct", "compound",
            names=c("siteid", "height", "colour"),
            subtypes=c("NC_INT", "NC_DOUBLE", "NC_SHORT"),
            dimsizes=list(NULL, NULL, c(3))) 

# Inquire about the types:
typeids <- grp.inq.nc(nc)$typeids

for (typeid in typeids) {
  print(type.inq.nc(nc, typeid))
}

close.nc(nc)
unlink(file1)

RNetCDF documentation built on Oct. 23, 2023, 9:06 a.m.