The programmer who is working with primitives often needs to communicate with the user. There are several classes to accomplish that.
The most flexible way to communicate with the user is to build a customized, window-based interface, as described in Using Tcl/Tk in Primitives. However, often it is sufficient to plot some data or to just construct strings and output them to files or to the standard output. To do the latter, use the classes pt_ifstream and pt_ofstream, which are derived from the standard C++ stream classes ifstream and ofstream, respectively. More sophisticated output can be obtained with the XGraph class, the histogram classes, and classes that interface to Tk for generating animated, interactive displays. All of these classes are summarized in this section.
The pt_ofstream class is used in the SDF primitive
. Include the header file pt_fstream.h. The pt_ofstream constructor is invoked in the setup method with the call to new. It would not work to invoke it in the constructor for the primitive, since the fileName parameter would not have been initialized. Notice that the setup method reclaims the memory allocated in previous runs (or previous invocations of the setup method) before creating a new pt_ofstream object. Notice that we are not using a wrapup method to reclaim the memory, since this method is not invoked if an error occurs during a run.
The most useful methods of the class are summarized in the table below. Using the XGraph class involves an invocation of the initialize method, some number of invocations of the addPoint method, followed by an invocation of the terminate method. Multiple data sets (currently up to 64) may be plotted together. They will each be given a distinctive color and/or line pattern. Within each data set, it is possible to break the connecting lines between points by calling the newTrace method.