nscl_logo_small.gif (2463 bytes)

swrite Command

HH00706_.jpg (6530 bytes)

Syntax

swrite [-format fmt] file spec1 [spec2 ... ]

Synopsis

Writes one or more spectra either to a file specified by name or a file opened with the Tcl open command.

Description

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:

The built in file formats are:

Format Specifier Format
ascii NSCL ASCII formatted file.
binary NSCL Binary (SMAUG) formatted file.
nsclascii NSCL ASCII formatted file.
nsclbinary NSCL Binary (SMAUG) formatted file.

SpecTcl's Spectrum I/O facility is user extensible. The set of file formats supported by swrite for any build of SpecTcl can be gotten by just typing:

swrite

Top

Examples

Writing to a file path.

swrite -format ascii /usr/users/TruCluster/users/fox/test.asc spec1 spec2 spec3

The spectra specified by spec1, spec2, spec3 are written in that order to the file /usr/users/TruCluster/users/fox/test.asc in NSCL ascii format.

Writing to a file opened with Tcl's open command

set file [open ~/test.asc w]
puts   $file "2 in ascii"
flush  $file
swrite -format ascii $file spec1 spec2
puts   $file "1 in binary"
flush  $file
swrite -format binary $file spec3
close $file

The file test.asc is created in the home directory.  First text is written to the file indicating that 2 spectra follow in ascii format.  Next spec1 and spec2 are written in ascii format.  Then text indicating that a single spectrum follows in binary format is written, followed by spec3 in binary notation. Note the use of the flush command above to ensure that the output buffered to the file by the puts commands is actually inserted into the file prior to the data created by the swrite command.

Writing to a pipe open on a process

set file [open {|gzip /usr/users/TruCluster/users/fox/test.asc} w]
swrite -format $file ascii spec1 spec2 spec3
close $file

Writes the spectra spec1, spec2 and spec3 to a pipe into gzip in ascii form.  The gzip pipe compresses this file producing /usr/users/Trucluster/users/fox/test.asc

Top


Last Modified: October 28, 2003 by: fox@nscl.msu.edu
© Copyright NSCL 1999, All rights reserved