str2nct: Convert between date character strings and netcdf time format

str2nctR Documentation

Convert between date character strings and netcdf time format

Description

Time indicators in netcdf use numbers of elapsed time units since a reference time. (Convertion used by CF standard.) str2nct evaluates the elapsed time of a date with respect to a reference time and generates a netcdf representation of the input character string(s). Currently available time units are number of minutes, hours, days, months, or years. nct2str makes the reverse conversion.

Usage

str2nct(str, t.unit, format = "%Y%m%d%H%M", 
        t.ref = "190001010000", format.ref = "%Y%m%d%H%M")
nct2str(nct, nct.unit, format="%Y%m%d%H%M") 

Arguments

str

A character string (or a vector of strings) specifying the date.

t.unit

The desired time unit. Currently available are: "T" delivering minutes, "H" delivering hours, "D" delivering days, "M" delivering months, "Y" delivering years.

format

The format of the input/output date string. Here we use conventions as in format. Note that all dates need have the same format if the input for str is a vector.

t.ref

The time reference to use. A character string.

format.ref

The format of the time reference.

nct

A netcdf time specification, typically a vector of integers, indicating the number of seconds, days etc. elabsed since a reference time.

nct.unit

The netcdf time unit used in the specification of argument nct. A string of the form "days since 1900-01-01 00:00:00"

Details

str2nct always returns integer numbers. So for example if t.unit="M" str ist truncated to the first 6 digits and the elabsed number of months is determined for the month of the date.

Note that the elapsed time starts with 0 if str is the same like t.ref.

Value

A single value or a vector with the elapsed time(s). The output has an attribute with name since.lab. This is the character string that can be used as the units attribute for time in the netcdf file.

Author(s)

Christoph Frei

See Also

Rdate2str

Examples

ts <- c("200706010000","200606020000","200606030000")
ts.ref="200001010000"
hh <- str2nct(str=ts,t.unit="D",t.ref=ts.ref)
hh

nct2str(nct=hh,nct.unit=attr(hh,"since.lab"))


metno/gibson documentation built on Feb. 12, 2024, 7:25 a.m.