Chapter 7. Extending SpecTcl spectrum file formats

The SpecTcl swrite and sread commands support two file formats out of the box. The binary format supports the old SMAUG analysis program spectrum format while the ascii format supports a simple zero suppressed ASCI format. In this chapter we will:

7.1. SpecTcl's spectrum file format infrastructure

SpecTcl depends on formatting objects to actually write files. The sread and swrite commands select a formatter and expect the formatter to take care of either reading a spectrum from the open file or writing a spectrum to an open file.

The two principle classes involved in selection and I/O are:


Defined in SpectrumFormatter.h. The base class for all formatters. Each concrete formatter must implement a Read and Write method.


Is a class that has only static methods (alternative to a singleton class) and static data. This class, given a format name, can return a formatter or indicate there is no match.

Any added formatter types must be registered with this class via its AddFormatter method. Registration associates a formatter with a format name string.

Reference information on these two classes is available in the programmer reference. When we provide an example, you will get sufficient information to stumble your way through writing a formatter and registering it with the factory.