get_datatype | R Documentation |
Provides information on the data type used in an LPJmL input/output file based on the 'datatype' attribute included in the file header.
get_datatype(header, fail = TRUE)
header |
Header list object as returned by |
fail |
Determines whether the function should fail if the datatype is
invalid (default: |
On success, the function returns a list object with three components:
type: R data type; can be used with what
parameter of readBin()
.
size: size of data type; can be used with size
parameter of
readBin()
.
signed: whether or not the data type is signed; can be used with signed
parameter of readBin()
.
If fail = FALSE
, the function returns NULL
if an invalid datatype is
provided.
read_header()
for reading headers from LPJmL input/output files.
create_header()
for creating headers from scratch.
get_headersize()
for determining the size of file headers.
## Not run:
# Read file header
header <- read_header("filename.clm")
# Open file for reading
fp <- file("filename.clm", "rb")
# Skip over file header
seek(fp, get_headersize(header))
# Read in file data
file_data <- readBin(
fp,
what = get_datatype(header)$type,
size = get_datatype(header)$size,
signed = get_datatype(header)$signed,
n = header$header["ncell"] * header$header["nbands"] *
header$header["nyear"] * header$header["nstep"],
endian = header[["endian"]]
)
# Close file
close(fp)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.