15.4 Customizing the Output Window


35104 getenv ({variable})
gets the value of the environment variable variable, if no input is given the values of all variables are listed
35107 setenv (variable, value)
sets the environment variable variable to the value value
35110 output ("file", option)
saves contents of the output window to the file file

XploRe provides a number of variables that customize the environment. Among others, a set of variables for modifying the output style in the output window is available:

Variable Default
   
outheadline "\r\nContents of %s\r\n\r\n"
        headline for arrays  
outlayerline "[,,%li,%li,%li,%li,%li,%li]\r\n"
        layerline for arrays  
outlineno "[%*li,]"
        line number style  
outmaxdata "2048"
        maximal output elements  
outputformat "% 8.5g"
        numeric output format string  
outputstringformat ""%s""
        string output style  

The defaults can be checked by using 35117 getenv to print out the value of a variable. For example,

  getenv("outmaxdata")
prints the string
  Contents of getenv
  [1,] "2048"
which implies that not more than 2048 data items are printed.

The variable outmaxdata can now be modified by using 35120 setenv :

  setenv("outmaxdata","100")
changes the number of data items to 100. Of course, several of the above variables can be modified simultaneously.

Let us now consider the format strings which control the style of the headline, the line number and the array dimension. Consider a $ 3\times 3\times 3$ array of normal random numbers as an example:

  randomize(0)
  x = normal(3,3,2)
  x
The default settings used in this extract from the output window:
outheadline $ \longrightarrow$ Contents of x
outlayerline $ \longrightarrow$ [,,1,1,1,1,1,1]
  [1,] -0.21293 -1.3052 -0.38946
outlineno $ {\longrightarrow}$ [2,] -1.0078 -1.4341 -1.5746
  [3,] 1.9502 0.69812 -0.26595
outlayerline $ \longrightarrow$ [,,2,1,1,1,1,1]
  [1,] 0.19947 -1.2245 0.20864
outlineno $ {\longrightarrow}$ [2,] -2.5033 -0.42123 -0.14358
  [3,] -0.49264 -0.72973 0.6273


15.4.1 Headline Style

The variable outheadline is used to influence the appearance of the headline in the output window. The default value is "\r\nContents of %s\r\n\r\n" where %s is a placeholder for the name of the variable. This results in the output of the words Contents of x, assuming x is the variable to be printed, followed by a blank line. Obviously, the combination of \r\n causes a line break.

It is possible to produce different outputs through the use of different format strings. No headline will be printed, when setenv ("outheadline", "") is used. Alternatively, an arbitrary headline, in this example a German title, can be produced.

randomize(0)
x = normal(2,2,2)
x
setenv ("outheadline", "Inhalt von %s\r\n\r\n")
x
35243 XLGiofmt04.xpl

prints now x in the following way:
  Contents of x
  [,,1,1,1,1,1,1]
  [1,] -0.21293   1.9502 
  [2,]  -1.0078  -1.3052 
  [,,2,1,1,1,1,1]
  [1,]  -1.4341 -0.38946 
  [2,]  0.69812  -1.5746 
  Inhalt von x
  [,,1,1,1,1,1,1]
  [1,] -0.21293   1.9502 
  [2,]  -1.0078  -1.3052 
  [,,2,1,1,1,1,1]
  [1,]  -1.4341 -0.38946 
  [2,]  0.69812  -1.5746

Note that we use the special characters \r\n to force a new line in the output window. \n is the new line character used in C. \r is the special C character which forces the cursor to jump to the first character in the current line. Throughout this book, we have mostly used

setenv ("outheadline", "Contents of %s\r\n") 
to suppress the blank line after the headline.


15.4.2 Layer Style

With outlayerline it is possible to influence the appearance of the layer style in the output window. It should be noted that the layer line only appears in the output window if the array consists of more than one layer. In the following example, the layer line does not appear, since x is a matrix:

  randomize(0)
  x = normal(2,2)
  x
shows
  Contents of x
  [1,] -0.21293   1.9502 
  [2,]  -1.0078  -1.3052
The default value for outlayerline is "[,,%li,%li,%li,%li,%li,%li]\r\n" where the %li are placeholders for the layer number. XploRe supports arrays up to eight dimensions. The first two dimensions are regular rows and columns of a matrix. These first two dimensions cannot be modified. Thus, we need at most six placeholders of the form %li (which represents a long integer, i.e. 64 bit on most machines) for the remaining dimensions.

It is possible to produce different outputs through the use of format strings. The following example shows the default output and the output after setting the layerline to the string "Layer: %s\r\n":

randomize(0)
x = normal(2,2,2)
x
setenv ("outlayerline", "Layer: %li\r\n")
x
35297 XLGiofmt05.xpl

The result is
  Contents of x
  [,,1,1,1,1,1,1]
  [1,] -0.21293   1.9502 
  [2,]  -1.0078  -1.3052 
  [,,2,1,1,1,1,1]
  [1,]  -1.4341 -0.38946 
  [2,]  0.69812  -1.5746 
  Contents of x
  Layer: 1
  [1,] -0.21293   1.9502 
  [2,]  -1.0078  -1.3052 
  Layer: 2
  [1,]  -1.4341 -0.38946 
  [2,]  0.69812  -1.5746

Note that in this last example we use only one placeholder %li instead of the potential six. Since this example contains only one additional layer beyond the regular rows and columns of a matrix -- normal(2,2,2) means 2 rows, 2 columns and 2 layers -- one placeholder is sufficient.


15.4.3 Line Number Style

With outlineno it is possible to influence the appearance of the line numbers of an array in the output window. The default value for this parameter is "[%*li,]", where %*li is a placeholder for the line number.

The following example shows the default output and the output after setting the layerline to the string "Line: %*li:

randomize(0)
x = normal(10,2)
x
setenv ("outlineno", "Line %*li:    ")
x
35343 XLGiofmt06.xpl

This yields
  Contents of x
  [ 1,] -0.21293  -2.5033 
  [ 2,]  -1.0078 -0.49264 
  [ 3,]   1.9502  -1.2245 
  [ 4,]  -1.3052 -0.42123 
  [ 5,]  -1.4341 -0.72973 
  [ 6,]  0.69812  0.20864 
  [ 7,] -0.38946 -0.14358 
  [ 8,]  -1.5746   0.6273 
  [ 9,] -0.26595  0.059032 
  [10,]  0.19947  0.44835 
  Contents of x
  Line  1:    -0.21293  -2.5033 
  Line  2:     -1.0078 -0.49264 
  Line  3:      1.9502  -1.2245 
  Line  4:     -1.3052 -0.42123 
  Line  5:     -1.4341 -0.72973 
  Line  6:     0.69812  0.20864 
  Line  7:    -0.38946 -0.14358 
  Line  8:     -1.5746   0.6273 
  Line  9:    -0.26595  0.059032 
  Line 10:     0.19947  0.44835

For matrices with more than 9 rows, a right-justified line number should be used. This is accomplished by including a * into the placeholder: The default setting [%*li,] uses this.


15.4.4 Value Formats and Lengths

This subsection considers the variables outputformat, outputstringformat and outmaxdata, which influence the format and the length of objects, that can be printed to the output window. All code examples for this section can be found in the quantlet 35398 XLGiofmt07.xpl .

outputformat sets the default output format for numeric arrays to % 8.5g. This format string means that the g-format is used with 5 decimals a total string length of 8. The variable outputformat can be changed now by using 35401 setenv :

setenv("outputformat","% 8.6g")
changes the number of decimals to 6. For outputformat one can use the same string format as for the function 35404 string . See Section 15.3 for examples on formatting numeric output.

The variable outputstringformat sets the default format for text arrays. The default is ""%s"". For example,

  x="a"~"bb"
  x
gives
  Contents of x
  [1,] "a" "bb"
in the output window. It is sometimes convenient to suppress the quotation marks. Using
setenv("outputstringformat","%s")
x
we obtain
  Contents of x
  [1,] a bb

Finally, the variable outmaxdata can change the number of maximal data items in the output window. The default is 2048. Note that the number of data items is also restricted by a size restriction of 32 Kilobytes for each output item.


15.4.5 Saving Output to a File

By default, all output is printed in the output window. The function 35470 output can save output additionally to a file. The function 35473 output must be called with one of the following options:

For example,
  x=uniform(2,2)
  x                              ; usual output
  output("output.txt","reset")
  x+2                            ; output goes also to output.txt
  output("output.txt","close")
  x+4                            ; usual output
  output("output.txt","append")
  x+8                            ; output goes also to output.txt
  output("output.txt","close")
35477 XLGiofmt08.xpl

This quantlet shows the first output of x as usual in the output window. The second output of x+2 goes to the output window and the file output.txt. Then the file is closed, such that the third output of x+4 is only printed in the output window. Now we open output.txt for appending. The output of x+8 goes to the output window and the file output.txt again. Finally, we close the file.