Laboratory Exercises For Computer Science 295

Lab 5: Graphical Display of Program Output

Lab 5: Graphical Display of Program Output

Goals: This lab introduces the XTANGO program for the graphical display of data.

Steps for this Lab:

  1. Reread Section 2.7 of Hartley's book, and write a paragraph summarizing how the XTANGO program works. While some mechanics for running XTANGO are slightly different on MathLAN, most the discussion applies without change.

  2. The XTANGO program uses a resource file to identify several properties of graphical objects. In order to use XTANGO, therefore, you will need to set a Unix environment variable, so the program can find the appropriate file. Also, you will want to set up an alias for the animator program, which is compiled in my account. To accomplish these tasks, add the following lines to your .cshrc file in your home directory (perhaps just before the final endif statement):
    
         # set environmental variable and access alias for XTANGO
         setenv XENVIRONMENT /u2/walker/parallel/xtango/xtango.res
         alias xtango "/u2/walker/parallel/xtango/animator/animator"
    
    The XTANGO program now should be accessible within every new hpterm window you open (including any future logins).

  3. Check that you can run the XTANGO program successfully by using it in conjunction with my program julia-test that does some simple computations for the Julia set. In particular, in any new hpterm window, type
    
         ~walker/parallel/sr/examples/julia-test | xtango 
    
    The first part of this command simply runs my program. The vertical line specifies that the output of my program will go directly into xtango. (In Unix jargon, you have piped the output of my julia-test into xtango.)

    If all runs correctly, a new window will appear on your screen. When you click the
    run animation button, a rough picture of the Julia set should appear.

    (If you get an error message that xtango is an unknown command or if an XTANGO window opens without a run animation button, be sure that you have added the above lines to your .cshrc file, that you have saved those changes, and that you are running in an hpterm window that was created after the changes to .cshrc were saved. If trouble persists, contact the instructor.)

  4. Review the output of julia-test by typing
    
    ~walker/parallel/sr/examples/julia-test | more
    
    This command pipes the output of julia-test into a keyboard display program more. (Alternatively, you could use pg in place of more.) more displays output a screen at a time. Hit the return key to advance the output a line at a time. Hit the space bar to move the the next screen.

    julia-test first specifies the overall coordinates for XTANGO's display box, and then the background color is set to white. Next, titles are printed in the display. The remaining lines indicate specific rectangles are to be printed in designated colors. Details of each command are given in Section 2.7 of Hartley's book.

    XTANGO works by keeping track of specific graphical objects by number, and each object must have a unique number. (The numbers, however, need not be sequential.) Thus, the second data item in each line for XTANGO is an identification number generated by the program.

  5. Run programs 2.20 and 2.21 from Section 2.7 in conjunction with XTANGO.
    (Remember that source code for these examples and all others in the text may be found in directory ~walker/parallel/sr/book/. Within that directory, the compiled programs are hello_world and sorter, respecively.)

  6. From lab 2, take a version of your fractals program, which prints the values of a results matrix. Revise your program, so that it prints an XTANGO rectangle command for each matrix point, rather than a value. For example, if your program uses a grid size of 5, then each square should have side 1.0/5 or 0.2. Choose your own range of colors. One simple approach is to declare an array, such as the following:
    
        const num_colors := 8
        var colors [0:num_colors]: string[10]
        colors[0] := "black"
        colors[1] := "white"
        colors[2] := "lightblue"
        colors[3] := "red"
        colors[4] := "cyan"
        colors[5] := "green"
        colors[6] := "orange"
        colors[7] := "maroon"
        colors[8] := "lightpink"
    
    With such an array, each value of results[i, j] could designate a specific color, or a range of values in results[i, j] could map to a specified color. Thus, a color for position (i, j) might be printed with either of the following expressions:
    
        writes(colors[results[i, j]]      )  #choice 1: 1 value  per color
        writes(colors[(results[i, j]+2)/3])  #choice 2: 3 values per color
    
    In either approach, it is suggested that you set the background color to colors[1]. Also, to save time, only print squares for colors other than this background color.

    For a complete set of possible colors, see /usr/lib/X11/rgb.txt .


Work to be turned in:


This document is available on the World Wide Web as

http://www.math.grin.edu/~walker/courses/295/lab5.html

created February 16, 1997
last revised February 17, 1997