You can save the values of a variable or expression to a file. You can subsequently visualize these values and compare them with the values in another visualizer--for example, the same variable later in the run, or during a totally separate execution of the program. This provides a convenient way of spotting changes in the values of a variable.
You can save the values of a variable or expression to a file for later use.
Use the command varsave to save the values of a variable or expression to a file. Its syntax is
varsave "filename" expression
where filename is the name of the file to which the data is to be saved, and expression is the variable or expression whose values are to be saved. For example,
varsave "alpha.data" alpha
saves the values of the variable alpha in the file alpha.data (in your current working directory within Prism).
varsave "/u/kathy/alpha2.data" alpha*2
saves the results of the expression alpha*2 in the file with the path name /u/kathy/alpha2.data.
Use the Save or Save As selection from a visualizer's File menu to save the visualizer's values to a file.
If you choose Save As, a dialog box appears in which you can specify the name of the file to which the values are to be saved; see Figure 5-15.
The highlighted directory is the current working directory. If you want to put the file there, simply type its name in the Save As box and click on OK.
If you want to put the file in another directory, click on the directory. (The parent directories of the current working directory are shown above it in the Directories list; its subdirectories are listed beneath it.) This will display the subdirectories of the directory you clicked on. You can traverse the directory structure in this manner until you find the directory in which you want to put the file, or, you can simply type the entire path name in the Save As box.
Choose the Save selection to save the values in the file you most recently specified. If you haven't specified a file, the values are saved in a file called noname.var in your current working directory in Prism.
Use the intrinsic varfile to bring values you have saved to a file back into Prism. Its syntax is:
varfile("filename")
where filename is the name of the file that contains the values you want to restore.
The varfile intrinsic is not available in MP Prism.
You can use the varfile intrinsic anywhere you could have used the original variable or expression that you saved to a file. For example, if you saved x:
varsave "x.var" x
then the command
print varfile("x.var")
is equivalent to
print x
Note that this allows you to save a variable's values, then print them during a later Prism session, without having a program loaded or running.
You can compare a variable or expression whose values have been saved in a file with another version of the variable or expression. This comparison could take place later in the same run of the program, during a subsequent run, or even during a second, simultaneous Prism session.
You can also compare the values with those of another variable, as long as both variables have the same base type (that is, you can't compare integers with floating-point numbers).
You can use the print or display command with the difference operator and the varfile intrinsic to perform a comparison between two versions of a variable or expression.
For example, if you saved x in the file x.var:
varsave "x.var" x
then the command
print x - varfile("x.var")
prints the difference between the current and saved values of x.
If an element is printed as 0, it is the same in both versions. If it is nonzero, its value is different in the two versions.
Use the Diff or Diff With selection from a visualizer's File menu to compare the visualizer's values with values stored in a file.
Choose Diff With to choose the file containing the values. It displays a dialog box like the one shown below.
The dialog box has the same format as the Save As dialog box described in " Saving the Values of a Variable". It lists the files found in your current working directory in Prism. Click on a file name, then click on OK to choose the file. Or type a file name in the Diff With text-entry box and click on OK.
Choose Diff to compare the visualizers values to those in the most recently specified file; if no file has been specified, values are compared to those in the file noname.var in your current working directory in Prism.
Once you have specified a file via Diff or Diff With, Prism creates a new visualizer that displays the difference in values between the visualizer and the file. If an element's value in the new visualizer is 0, the value is the same in both versions. If it is nonzero, it is different in the two versions.
You can work with this visualizer as you would any visualizer. For example, you can change the representation and display summary statistics.