Learn R Programming

dplR (version 1.7.6)

write.crn: Write Tucson Format Chronology File

Description

This function writes a chronology to a Tucson (decadal) format file.

Usage

write.crn(crn, fname, header = NULL, append = FALSE)

Value

fname

Arguments

crn

a data.frame containing a tree-ring chronology with two columns of the type produced by chron. The first column contains the mean value chronology, the second column gives the sample depth. Years for the chronology are determined from the row names. The chronology ID is determined from the first column name.

fname

a character vector giving the file name of the crn file.

header

a list giving information for the header of the file. If NULL then no header information will be written.

append

logical flag indicating whether to append this chronology to an existing file.

Author

Andy Bunn. Patched and improved by Mikko Korpela.

Details

This writes a standard crn file as defined according to the standards of the ITRDB at https://www1.ncdc.noaa.gov/pub/data/paleo/treering/treeinfo.txt. This is the decadal or Tucson format. It is an ASCII file and machine readable by the standard dendrochronology programs. Header information for the chronology can be written according to the International Tree Ring Data Bank (ITRDB) standard. The header standard is not very reliable however and should be thought of as experimental here. Do not try to write headers using dplR to submit to the ITRDB. When submitting to the ITRDB, you can enter the metadata via their website. If you insist however, the header information is given as a list and must be formatted with the following:

DescriptionNameClassMax Width
Site IDsite.idcharacter6
Site Namesite.namecharacter52
Species Codespp.codecharacter4
State or Countrystate.countrycharacter13
Speciessppcharacter18
Elevationelevcharacter5
Latitudelatcharacter or numeric5
Longitudelongcharacter or numeric5
First Yearfirst.yrcharacter or numeric4
Last Yearlast.yrcharacter or numeric4
Lead Investigatorlead.invscharacter63
Completion Datecomp.datecharacter8

See examples for a correctly formatted header list. If the width of the fields is less than the max width, then the fields will be padded to the right length when written. Note that lat and long are really lat*100 or long*100 and given as integral values. E.g., 37 degrees 30 minutes would be given as 3750.

This function takes a single chronology with sample depth as input. This means that it will fail if given output from chron where prewhiten == TRUE. However, more than one chronology can be appended to the bottom of an existing file (e.g., standard and residual) with a second call to write.crn. However, the ITRDB recommends saving and publishing only one chronology per file. The examples section shows how to circumvent this. The output from this function might be suitable for publication on the ITRDB although the header writing is clunky (see above) and rwl files are much better than crn files in terms of usefulness on the ITRDB.

See Also

chron, read.crn

Examples

Run this code
library(utils)
data(ca533)
ca533.rwi <- detrend(rwl = ca533, method = "ModNegExp")
ca533.crn <- chron(ca533.rwi)
fname1 <- write.crn(ca533.crn, tempfile(fileext=".crn"))
print(fname1) # tempfile used for output

## Put the standard and residual chronologies in a single file
## with ITRDB header info on top. Not recommended.
ca533.crn <- chron(ca533.rwi, prewhiten = TRUE)
ca533.hdr <- list(site.id = "CAM", site.name = "Campito Mountain",
                  spp.code = "PILO", state.country = "California",
                  spp = "Bristlecone Pine", elev = "3400M", lat = 3730,
                  long = -11813, first.yr = 626, last.yr = 1983,
                  lead.invs = "Donald A. Graybill, V.C. LaMarche, Jr.",
                  comp.date = "Nov1983")
fname2 <- write.crn(ca533.crn[, -2], tempfile(fileext=".crn"),
                    header = ca533.hdr)
write.crn(ca533.crn[, -1], fname2, append = TRUE)
print(fname2) # tempfile used for output

unlink(c(fname1, fname2)) # remove the files

Run the code above in your browser using DataLab