write.TSD: Writes files using the Time Step Data format.

View source: R/write.TSD.R

write.TSDR Documentation

Writes files using the Time Step Data format.

Description

See the documentation on echoIBM for specification of the Time Step Data format (TSD). Handling of missing values differ between data types, as given in the table below, which gives the values that are stored in the file when given as NA, NaN, NA_real_, or NA_integer_ in the data:

Value Data type
floa doub shrt long
NA 0 NaN 0 NA
NaN NaN NaN 0 NA
NA_real_ NaN NA 0 NA
NA_integer_ NaN NA 0 NA

and similar for the complex data types.

Usage

write.TSD(
  x,
  con,
  t = "all",
  var = "all",
  header = NULL,
  numt = NULL,
  dimension = TRUE,
  ts = "last",
  reserve = 0,
  keep.null = TRUE,
  dup = FALSE,
  endian = .Platform$endian,
  append = FALSE,
  ow = TRUE,
  keep.float = FALSE,
  use.raw = 1000,
  ...
)

Arguments

x

is the list containing the data to write.

con

is the connection object or a character string naming the output file.

t

is a vector of the time steps to write (in the range [1, number of pings]). If none of the elements of 't' are in [1, number of pings], only the header is written. If t == "all", all time points are written and if t == "none", none of the time points are written.

var

is a vector of the variables to be written, either given as a character vector holding the names of the variables, as specified in the TSD-format, or as the number of the variables in 'labl', if 'labl' is known. If var == "all", all varialbes are written and if var == "none", none of the variables are written.

header

is a list containing one or more of the following two elements ("nvar" and "lvar" are always extracted from the data as of 2011-12-06):

numt

is the number of time points of the data 'x' overriding any existing information about the number of time steps, given in 'header' or 'x' (intended to only be specified if all time steps are arranged in the same vector for all variables).

dimension

is an object specifying whether the dimensions of the variables at each time step are to be stored in the file. 'dimension' may have 4 values:

ts

is a numeric vector specifying the rules for regarding the last dimensions of arrays as time: If the number of dimensions of an array is included in the set 'ts' the last dimension of that array is considered to be along time, so that if ts = 3 and we wish to write an array of dimension [3, 4, 2], this array will be written as two [3, 4] arrays. 'ts' is utilized through seq_along(dim(x))[ts], so that if ts = -2 matrices are not regarded as having time along the second dimension.

reserve

The number of time steps to reserve for future appending to the file (in which case 'reserve' rows of zeros are appended in 'lvar' in the header).

keep.null

Logical: If FALSE elements of length 0 should be discarded from the data, in which case a numerical 'var' would represent indices of 'x' AFTER empty elements have been removed.

dup

Logical: If TRUE allow for duplicated variable label. If dup = FALSE (default) all variables with the same label as a previous variable in the input list 'x' are removed.

endian

The endian of the file, defaulted to .Platform$endian (changed from "big" by Arne Johannes Holmin 2012-07-31).

append

is TRUE if data is to be appended to the end of 'con' (only valid when 'con' is a character string), in which case the header is not written. No check made for compatibility to the existing file.

ow

is TRUE if the user wish to overwrite existing file.

keep.float

Logical: If TRUE scan the data for double presicion (large numbers). Use this to ensure no loss of presicion (TIME DEMANDING (0.2 sec for 1324*500*117 values)).

use.raw

Either a logical where TRUE reads the time steps (which must be in a sequence) first and then converts to appropriate values, or as the total numer of values of each time step below which the raw method is used.

...

is to allow variables passed on from other methods.

Examples

## Not run: 
# Write some data to a TSD file (all variable must have 4 character names):
dat <- list(
	var1=list(
		array(runif(2*3*4), dim=c(2,3,4)), 
		array(runif(7*4), dim=c(7,4))
		), 
	var2=list(
	
		c("Time step 1", "ebaerb"), 
		c("Last time step")
		), 
	var3=list(
		complex(real=1:12, imaginary=runif(12)), 
		NULL
		)
	)
TSDfile <- tempfile()
write.TSD(dat, TSDfile, numt=2)
datread <- read.TSD(TSDfile, t="all")

# Differs in precision of the first variable 'var1':
all.equal(dat, datread)

# Set the first varialbe to double precision:
write.TSD(dat, TSDfile, numt=2, header=list(dtyp=list(var1="doub")))
datread <- read.TSD(TSDfile, t="all")
all.equal(dat, datread)

## End(Not run)


arnejohannesholmin/TSD documentation built on April 14, 2024, 5:29 a.m.