Visualizing images

This module shows you how to create output workstations and how to send view objects to them for viewing. You will also see how you can send the same object to different output workstation.

Creating output workstations

After you have created a view object, in order to view the object you must create an output workstation and send your view objects to the workstation. You can create several workstations and send view objects to any or all of them.

There are three different types of workstation classes you can use for creating workstation objects for sending view objects to:

  1. XWorkstation for plotting to an X11 window.
  2. NcgmWorkstation for storing graphics in NCGM format.
  3. PSWorkstation for storing graphics in various flavors of PostScript.
Each of the above workstation objects has resources for controlling various aspects of the output, such as metafile name for NCGM output, pausing in an X11 window, selecting PS or EPS output for PostScript, and so on. Consult the reference pages for these workstations for details. All of the above classes are subclassed from the Workstation class. The Workstation class has a multitude of resources itself, such as setting color maps. See the reference page for the Workstation class for details.

Only one NcgmWorkstation can be created at a time in an application, but up to 15 independent XWorkstations or PSWorkstations can be created.

Workstations are created in NCL by using the create expression. For example, the following code would create an instance of a PostScript workstation that produces EPS.

     xworkid = create "simple" psWorkstationClass defaultapp
         "wkPSFormat" : "EPS"
         "wkBackgroundColor"  : (/ 1., 1., 1. /)
     end create

The workstation name "simple" is used as the base name for the EPS output, so that when view objects are drawn to xworkid, the output file will have the name "simple.eps".

Sending view objects to output workstations

The NCL function used to send a picture represented by a viewable object to an output device is draw. This function takes a single argument that contains an array of one or more view object identifiers. The objects identified in the argument to the NCL draw procedure are sent to the workstation identified as the parent in the create expression that was used to create the object.

Here is a simple example:

;
; NCL script that creates an output workstation and sends view
; objects to it.

;
; Create an X11 output workstation.
;

xworkid = create "x_work" xWorkstationClass defaultapp
    "wkPause" : "True"
end create

;
; Create a couple of TextItem objects.
;

text_id1 = create "Text" textItemClass xworkid
    "txPosXF": 0.5
    "txPosYF": 0.4
    "txString": "Text String 1"
end create
text_id2 = create "Text" textItemClass xworkid
    "txPosXF": 0.5
    "txPosYF": 0.6
    "txString": "Text String 2"
end create

;
; Draw one string on the workstation and pause.
;

draw(text_id1)
frame(xworkid)

;
; Draw both strings on the workstation and pause.
;

draw((/text_id1,text_id2/))
frame(xworkid)

For most applications, you will call the NCL procedure frame after a draw in order to terminate an image. For more precise control, you may want to use the NCL procedures update and clear.

Sending the same object to one or more output workstations

Sometimes you would like to send the same object to more than one workstation. The NCL draw procedure sends an object identified in its argument to the workstation whose identifier was specified in the create expression that was used to create the object. In order to send an object to a different workstation than the one identified in its creation, it is necessary to specify a new parent for the object. This can be done by using the NhlChangeWorkstation procedure.

Here is a simple example of sending the same object to two different workstations:

;
; Create a PS output workstation with a white background color.
;

psworkid = create "simple" psWorkstationClass defaultapp
    "wkBackgroundColor"  : (/ 1., 1., 1. /)
end create

;
; Create an X11 workstation.
;

xworkid = create "X11" xWorkstationClass defaultapp
    "wkPause" : "True"
    "wkBackgroundColor"  : (/ 1., 1., 1. /)
end create

;
; Create data for an XyPlot
;

dataid = create "xyData" coordArraysClass defaultapp
    "caXArray": (/0.0, 0.1, 0.5, 0.9, 1.0, 0.9, 0.5, 0.1, 0.0/)
    "caYArray": (/0.5, 0.9, 1.0, 0.9, 0.5, 0.1, 0.0, 0.1, 0.5/)
end create

;
; Create a simple XyPlot object.
;

plot_id = create "Box" xyPlotClass xworkid
   "xyCoordData": dataid
end create

;
; Send the XyPlot to the X11 workstation.
;

draw(plot_id)
frame(xworkid)

;
; Send the XyPlot to the PS workstation.
;

NhlChangeWorkstation(plot_id,psworkid)
draw(plot_id)
frame(psworkid)

User Guide Control Panel

NG4.1 Home, Index, Examples, Glossary, Feedback, UG Contents, UG WhereAmI?


$Revision: 1.7 $ $Date: 1998/06/15 22:08:46 $