Common Pitfalls


Getting All of Your Output

A problem that often causes the loss of part (or all) of the last frame of a graphics session occurs because many of the NCAR Graphics LLUs do not automatically advance to a new picture when they are called. This is to allow you to write multiple graphics on a single picture and include graphics from multiple utilities. The user may forget to advance to a new picture at the end of an application as well. At the end of a job you must remember to issue a call to flush the graphics buffers (CALL SFLUSH), or a call to advance to the next picture (CALL FRAME) which will call SFLUSH. For details on SFLUSH or FRAME, consult the man pages.

Output Attributes Changing at the Wrong Time

For reasons of efficiency, SPPS maintains an internal buffer which accumulates polyline coordinates. This buffer is automatically flushed when it is full, or when FRAME is called, or it can be flushed by the user with a call to SFLUSH. If polyline attributes are changed between SPPS calls that produce lines, then failure to flush the polyline buffer in SPPS between the line-producing calls can cause unexpected results.

For example, if you set line color to pink, then call LINE to draw a line, then set line color to blue and call LINE to draw another line, and then call FRAME, you will get two blue lines unless you flush the polyline buffer after drawing the first line. This is because the order in which things are done is: put line color pink to the output stream; put out coordinates for the first line call in the SPPS buffer; put line color blue to the output stream; put coordinates for the second line in the SPPS buffer; put polyline elements to the output stream when the call to FRAME is encountered. If you are using direct GKS calls (such as GPL), then the buffer flush is not necessary because the buffer is a feature of SPPS and not a feature of GKS.

Getting the Font You Want

All of the Hershey fonts available through GSTXFP are available via the Plotchar package. PostScript source documentation for Plotchar is available. Plotchar also supports a number of filled, scalable, fonts. If you are using a PostScript output workstation, then the fonts of the PostScript interpreter used to draw the plots will be used.

The Dot Polymarker Cannot be Scaled

The GKS standard requires that marker type 1 always be displayed as the smallest possible dot. For this reason, the dot polymarker will not be affected by the marker size scale factor as set by GSMKSC. To get filled dots of any size and color use the NGDOTS subroutine.

Precedence of metafile names

If you use NGSETI (or escape function -1391) to set a value for 'ME' to provide a metafile name within your code, this name will be superceded by the name supplied as the setting of the environment variable NCARG_GKS_OUTPUT. Make sure that NCARG_GKS_OUTPUT is not set when specifying a metafile name in your code.

See the man pages for NGSETI, NGSETR, NGSETC, and ngmisc_params for setting values for NCAR GKS escape functions, such as a metafile name.

See ncargex to run example pgkex26 showing how to name metafiles within your code.

Positioning Character Strings Where You Want Them

When positioning characters it can often be convenient to use normalized device coordinates in the range of 0. to 1. in both dimensions, as opposed to an arbitrary set of units as defined by the user coordinate system. You should generate the desired text output, then return to the original set of user coordinates. The four steps involved are:
  1. Call GQCNTN (ERRIND, TRNUM) to get TRNUM, the current normalization transformation number.
  2. If TRNUM is not 0, invoke normalization transformation 0 with a call to GSELNT (0).
  3. Write your text using Plotchar, or GTX.
  4. Return to the original normalization transformation, TRNUM, with a call to GSELNT (TRNUM).

Links: GKS Index, GKS Home