Writes one or more spectra either to a file specified by name or a file opened with the Tcl open command.
Writes the spectra specified by
spec1...
specn to file. The
spectra are written in the order they are specified. The optional
-format switch indicates that the next parameter
specifies the file format. The
file parameter specifies the file to which
the spectrum will be written. The file parameter can be:
A directory path to a file in which case the file is created, written and closed.
A file id returned from the Tcl open command in which case the file id is written to in its current position and remains open after the write.
The -format option describes how the file will be
written. See the sread command for more information
about the file formats. THere are two formats (each has two
names):
An ASCII format. Each spectrum consists of a header and a set of lines containing channel coordinate/value pairs for all nonzero channels in the spectrum.
SMAUG binary format. This format is not recommended unless you have old SMAUG analysis tools you intend to use on the files.
This format provides a description of spectra and their contents in JavaScript Object Notation (JSON). Since spectra are an array of objects in the file and JSON files must be fully read to be parsed, it is not possible to read more than the first spectrum from a JSON file.
The schema for the objects written is descdribed in the header SpectrumFormatterJson.h and will be documented further in another document at a later time.
Note that when writing spectra, bin numbers and corresponding axis coordinates are gotten from the underlying Root spectra.
Example 1. Writing spectra to file by filename
swrite -format ascii somespectra.spc raw.00 raw.01 raw02
Three psectra are written to file into the file somespectra.spc.
Example 2. Writing to a file descriptor
set fd [open "|gzip > somespectra.gz" w]
swrite -format ascii $fd raw.00 raw.01 raw.02
The spectra are written to a pipeline created by the Tcl open command that compresses them using gzip into a file name somepsectra.gz. Note that the open command will require the spaces before and after the output redirection character (>) unlike bash.