Using Printers and Plotters for Generating Graphics

The preceding chapter described how to generate graphic images on your CRT display. In this chapter, we discuss selecting external printing and plotting devices which you can use to generate graphics on paper. (See the HP BASIC Advanced Programming Techniques manual for more information on "external" CRT displays that can be connected to your computer through display interfaces.)

NOTE
The Manual Examples disk (/usr/lib/rmb/demo/manex for BASIC/UX users) contains programs found in this chapter. As you read through the following sections, load the appropriate program and run it. Experiment with the programs until you are familiar with the demonstrated concepts and techniques. Remember that on BASIC/WS, some of the programs require the MAT (matrix) BIN file.

Dumping Raster Images to Printers

After generating an image on your CRT display, you can print it on paper using a printer. This operation is called a graphics dump or screen dump. It is accomplished by copying data from the frame buffer to be reproduced dot for dot on the printer. For information on putting a screen dump into a file, read the section "Dumping Raster Images to a File."

First, the image must be generated on any CRT display. BASIC "takes a snapshot" of the graphics screen at some point in time, and sends it to a printer. BASIC doesn't care how the dots were turned on or off. Thus, all CRT graphics capabilities (except color) are available.
NOTE
You can send a color dump display to a PaintJet(TM) using HP BASIC/WS with the GDUMP_C utility. For more information on this, read the "BASIC Utilities Library" section of the Installing and Maintaining HP BASIC/WS manual.

Dumping to HP Raster Interface Standard Devices

If your printer conforms to the HP Raster Interface Standard, dumping graphic images is trivial. For example:

 
100   DUMP DEVICE IS 701
110   DUMP GRAPHICS
 

or

 100   DUMP GRAPHICS #701 

To determine whether or not your printer conforms to this standard, see your printer's manual or the configuration reference.

Both of these program segments would take the image last specified in the graphics frame buffer (the internal CRT display by default) and send it to the printer at address 701. (If no source device is specified, the image is taken from the last active CRT or it is the default graphics display.) Address 701 is the default factory setting for printers.

Dumping from a Color Display

When dumping an image from a color display to a printer, the state of each bit sent to the dump device is calculated by performing an inclusive OR operation on all color-plane bits for each pixel (in other words, a dot is printed if the pen used to write the dot was not equal to 0). Thus, no color information is dumped.

Dumping from a High-Resolution Display

If the source device is a high-resolution display, the image will not fit on one page of most HP printers. In such cases, use only the portion of the screen that is dumped to the printer. You can see which portion is not used by drawing a grid, for instance, and then dumping it to the printer. When you see which part is not displayed on the printer, you can change the region of the graphics display (with VIEWPORT, for example) so that you do not use that region.

Using the DUMP GRAPHICS Key

The [DUMP GRAPHICS] key (on an ITF keyboard, press [Shift] and the unlabeled key above the + on the numeric keypad) will also dump a graphics display to a printer. If a DUMP DEVICE IS statement has not been executed, the dump device is expected to be at address 701.

Aborting Graphics Dumps

If a DUMP GRAPHICS operation is aborted with the [CLR I/O] key ([Break] on an ITF keyboard), the printer may or may not terminate its graphics mode. Sending 192 null characters (ASCII code zero) to a printer such as an HP 9876 terminates its graphics mode. For example:

 OUTPUT Dump_dev USING "#,K";RPT$(CHR$(0),192) 

To dump a graphics image from an external color monitor that is interfaced through an HP 98627A at address 28, you could execute either of the following:

 
DUMP DEVICE IS Dump_dev
DUMP GRAPHICS 28
 

or

 DUMP GRAPHICS 28 TO #Dump_dev 

Expanded Dumps

If you want the image to be twice as large in each dimension as the actual screen size, you can execute the following two statements:

 
100   DUMP DEVICE IS 701,EXPANDED
110   DUMP GRAPHICS
 

This will cause the dumped image to be four times larger than it would be if ,EXPANDED had not been specified. Each dot is represented by a 2×2 square of dots, and the resulting image is rotated 90° to allow more of it to fit on the page. Depending on your screen size and printer size, the image being dumped may not entirely fit on the printer. If it doesn't, it will be truncated.

Dumping Displays with Non-Square Pixels

If you have an HP 98542A or HP 98543A display, the pixels are not square. Images are not distorted because of this, however, because the BASIC system compensates for the rectangularity. Also, the image is not distorted when dumping graphics because the BASIC system compensates for the non-square pixels.

For machines which have a display with non-square pixels, a non-expanded DUMP GRAPHICS will produce an image that matches the CRT only if no alpha appears in the graphics planes. Since most printers print square pixels, this routine treats graphics pixel pairs as single elements and prints one square for each pixel pair in the frame buffer. Because alpha works with individual pixels and not with pixel pairs, mixed alpha and graphics will appear blurred on a DUMP GRAPHICS non-expanded output. Using the EXPANDED option causes the vertical length (the height on the CRT) to be doubled as before, but dumps each separate pixel. In this mode, mixed alpha and graphics will appear the same on the dump as on the CRT. Note that on multiplane bit-mapped displays, only graphics write-enabled planes are dumped.

Dumping to Non-Standard Printers

If your printer that does not conform to the HP Raster Interface Standard, all is not lost. It must, however, be capable of printing raster-image bit patterns. There are two main methods by which printers print bit-sequences:

Example of Dumping to an Non-standard Printer

The HP 82905A printer uses the latter method listed above. The image (which is printed sideways) takes a GSTOREd image and breaks the 16-bit integers into two 8-bit bytes, and sends them to the printer one row at a time. This is the reason for the Hi$ and Lo$ -- the high-order (left) and low-order (right) bytes of the current integer. For an example of a subprogram that dumps graphics from a medium-resolution display to an HP82905A printer, see the file DumpGraph on the Manual Examples disk or in /usr/lib/rmb/demo/manex.

To DUMP GRAPHICS to other types of printers, you can modify the preceding subprogram appropriately for the destination device. See your printer's manual for information about its "raster-image" mode.

Negative Images

Note that on a CRT, an "on" pixel is light on an otherwise dark background, and on a printer, an "on" pixel is dark on an otherwise light background. Thus, the hard copy is a negative image of the image on the screen. To dump light images on a dark background, you can use the BINCMP function to complement the bits in every word before you send the image to the printer, or you can invert the bits of an integer by using this program segment:

 
IF N=-32768 THEN
  N=32767
ELSE
  N=-N-1
END IF
 

The reason for the subtraction is that HP 9000 Series computers use two's-complement representation of integers. Also, -32 768 is a special case because you cannot negate -32 768 in an integer; +32 768 cannot be represented in a signed, sixteen-bit, two's-complement number.

Dumping Raster Images to a File

This section covers the keywords required to dump an alphanumeric or graphics display to a specified file.

Specifying the File that Receives the Raster Dump

The DUMP DEVICE IS statement specifies which file receives the data when either a DUMP ALPHA or DUMP GRAPHICS statement is executed without a device selector. The syntax used for DUMP DEVICE IS is as follows:


DUMP DEVICE IS file_specifier,[EXPANDED]

where the file_specifier must be a BDAT or an HP-UX file which is to receive the output from the raster dump. The optional parameter EXPANDED doubles the size of the image and rotates it 90 degrees.

Example

This example dumps a raster image to a BDAT file and then dumps that file to a printer.

 
100  ! Draw a picture and dump it to a BDAT file named "Picture"
110  ! then output the file to a printer.
120  INTEGER I
130  CREATE BDAT "Picture",1  ! Creates a file named "Picture".
140  DUMP DEVICE IS "Picture" ! Assigns dump device to be the file
150                           ! named "Picture".
160  ! Put statements for drawing your picture here.
 .
 .
 .
300  DUMP GRAPHICS            ! Dump raster images to the file
310                           ! named "Picture".
320  ! Assign file names for dumping the file "Picture" to a
330  ! printer.
340  ASSIGN @File TO "Picture";FORMAT OFF
350  ASSIGN @Printer TO 701;FORMAT OFF
360  ON END @File GOTO Done
370  ! Dump the file "Picture" to the printer.
380  LOOP
390    ENTER @File;I
400    OUTPUT @Printer;I
410  END LOOP
420 Done:!
430  ! Close I/O path names
440  ASSIGN @File TO *
450  ASSIGN @Printer TO *
 

Using Plotters

In Chapter 1, the program listings contained a line which said:

 PLOTTER IS CRT,"INTERNAL" 

This caused the computer to activate the internal CRT graphics raster as the plotting device, directing all subsequent commands to the screen.

Selecting a Plotter

If you want a plotter to be the output device, only the PLOTTER IS statement needs to be changed. If your plotter is at interface select code 7 and address 5 (the factory settings), the modified statement would be:

 PLOTTER IS 705,"HPGL" 

Specifying HPGL tells BASIC to generate HPGL commands when it executes graphics statements, and to send them to the current plotting device.

Plotter Graphics with HPGL Commands

When you execute BASIC graphics statements on an HP plotter, you can intersperse your own HPGL commands between the BASIC commands. HPGL commands can be sent to the device with OUTPUT statements; however, the preferred way is to use the GSEND statement.

 
PLOTTER IS 705,"HPGL"
FRAME
GSEND "HPGL command(s)"
MOVE X,Y             
GSEND "HPGL command(s)"
DRAW X+10,Y-20
 

HPGL command sequences are terminated by a line-feed, a semicolon, or an EOI indication, which is sent by the HP-IB END keyword. Individual commands within a sequence are typically delimited by semicolons. Note that the GSEND command sends a carriage return/line feed after the specified string.

Many HPGL commands are available, but which ones you will be able to use depend on the device itself. Plotters are not the only devices which use HPGL; some digitizers and graphics tablets do also. By their nature, however, they use a different subset of commands than plotters do. Following are a few of the more common or useful HPGL commands.

Example: Controlling Pen Speed

To control pen velocity, you could have a statement:

 GSEND "VS10;" 

"VS" stands for "Velocity Select" and the "10" specifies centimeters per second. This statement specifies a maximum speed rather than an only speed. The range and resolution of pen speeds, and default maximum speed depend on the plotter.

Example: Controlling Pen Force

On the HP 7580 and HP 7585 drafting plotters, you can specify the amount of force pressing the pen tip to the drawing medium to match pen type to drawing medium. An example statement is:

 GSEND "FS3,6;" 

This statement (Force Select) specifies that pen number 6 should be pressed onto the drawing medium with force number 3. The range in force depends on the plotter.

Example: Selecting Character Sets

Some plotters contain internal character sets which may be more pleasing to the eye or more appropriate for your application than the BASIC character set. For example, to use Character Set 1, type:

 GSEND "CS1;" 

Error Detection when Using HPGL Commands

If you make an error when using HPGL commands, it is possible to interrogate the plotting device and determine the problem. The following statements in an error-trapping routine would determine the type of error that occurred:

 
GSEND "OE;"
ENTER 705;Error
 

After these statements have executed, the variable Error will contain the number of the most recent error. What the error code means depends on the particular device used.

This is not an exhaustive list of HPGL commands. A thorough understanding of HPGL can only be obtained by combining information from the owner's manual of the particular device you have with actual hands-on experience.

Plotting to Files

The preceding PLOTTER IS statements were used to direct HPGL commands to a plotter. You can also direct these commands to a file. This is useful when you want to check what is being sent to a plotter, or when you want to generate a special sequence of HPGL commands that you cannot generate with BASIC graphics statements. It is also useful when using an SRM plotter spooler, as discussed in a subsequent section.

The following statements would send subsequent plotter output (HPGL commands) a file named Plot.

 
CREATE BDAT "Plot:,700",20
PLOTTER IS "Plot:,700";"HPGL"
FRAME
MOVE 0,0
DRAW 100,100
MOVE 0,100
DRAW 100,0
MOVE 50,50
CSIZE 15
LABEL "Big X"
PLOTTER IS CRT,"INTERNAL"
 

Plot must be a BDAT file. Another PLOTTER IS statement, SCRATCH A, or GINIT statement closes the file. A Reset also closes the file.

Plotter Paper Sizes

The PLOTTER IS statement also lets you specify a non-default paper size. Here is the general syntax you can use; just substitute the limits (in millimeters) for the four parameters:

 PLOTTER IS "File","HPGL",  Xmin, Xmax, Ymin, Ymax  

See the HP BASIC Language Reference and your plotter's manual for additional information.

Limitations

If you perform an operation on one plotting device and send the plot to another device which does not support that operation, it won't work. For example, area fills, which are valid operations on most displays, are not available on plotters. Color map operations, which are valid on displays, are not valid on a plotter. Erasing lines can be done on displays, but, naturally, not on a hard-copy plotter. On the other hand, HPGL commands will be interpreted correctly by a hard-copy plotter, but not by a display.

Using GSEND with PLOTTER IS Files

This statement sends a string of characters to the current PLOTTER IS device, which may be a file or a plotter.

 GSEND "LBThis is an example HPGL command string."& CHR$(3)& ";" 

The string is to contain HPGL commands. GSEND is useful when the PLOTTER IS device is a file, since it is not possible to OUTPUT an HPGL command to the file while it is the PLOTTER IS device.

 
CREATE BDAT "Plot:,700",20
PLOTTER IS "Plot:,700";"HPGL"
FRAME
MOVE 0,0
DRAW 100,100
MOVE 0,100
DRAW 100,0
MOVE 20,20
GSEND "CS2;"
GSEND "LBThis is X in the plotter's character set 2."& CHR$(3)& ";"
PLOTTER IS CRT,"INTERNAL"
 

Note that HPGL syntax is not checked by the BASIC system. Therefore, you will need to take extra care when using HPGL commands in this manner.

Using SRM Plotter Spoolers (Not supported on the Series 700)

The SRM system not only provides shared access to plotters, but also manages their use so that workstations never need to wait for output to be generated.

What Are Spoolers?

To use shared plotters, you place files to be output into a special directory where they are held until the plotter is free. This method is called "spooling," and the directory where the files are kept is called the "spooler directory." After a file is placed in a spooler directory, the workstation is free to do other processing.

SRM/UX Plotter Spoolers

For information on installing and using SRM/UX spoolers refer to section "Establishing the SRM /UX Spooling Environment" in SRM/UX System Administrator's and Users Guide manual.

Setting Up a Plotter Spooler

Spooler directories are created for the SRM server's use when the shared peripherals are installed on the SRM system. Setting up a spooler directory is explained in the "Interfaces and Peripherals" chapter of the SRM Managers Guide. The examples in this section assume that a spooler directory named PL (for "PLotter") has been created in the SRM root directory.

Preparing Plotters

If your plotter does not feed paper automatically, a message appears on the SRM server's screen indicating that the plotter needs to be set up. After you put paper in the plotter, you may begin plotting by using the server's SPOOL CONTINUE command (described in the SRM Managers Guide). Plotters with automatic paper feed require no operator intervention.

Plotter Spooling

These are the steps in using the SRM plotter spooler:

  1. Create a file.
  2. Specify it as the PLOTTER IS device.
  3. Perform BASIC or HPGL plotting operations.
  4. When finished, close the file and, if it is not already there, COPY or RENAME it into the spooler directory.
  5. Wait for the file to be output to the plotter.

Example of Plotting to a File

You can use PLOTTER IS to send data to a file, which you can later send to an SRM plotter. The following command sequence illustrates this spooling method:

 
CREATE BDAT "/PL/Plot_file",1
PLOTTER IS "/PL/Plot_file"
FRAME
MOVE 0,0
DRAW 100,100
MOVE 0,100
DRAW 100,0
GSEND "CS2;"
GSEND "LBThis is X in the plotter's character set 2."& CHR$(3)& ";"
PLOTTER IS CRT,"INTERNAL"
 

PLOTTER IS works only with BDAT files. Because the SRM 1.0 operating system's spooling works only with ASCII files, you cannot use PLOTTER IS for plotter spooling with that version of SRM.

Checking the Spooler's Status

The SRM spooler waits until the file is non-empty and closed before sending its contents to the output device. If your file is not plotted within a reasonable amount of time, you may not have closed it. You can verify that your file is ready to be plotted by cataloging the spooler directory:

 CAT "/PL" [Return] or| [ENTER]  

The open status (OPEN STAT) of the file currently being printed or plotted is listed as locked (LOCK). Files currently being written to the spooler directory are listed as OPEN. Files that do not have a status word in the catalog are ready for plotting.

Version 2.0 (and later versions) of the SRM operating system allow BDAT files to be sent to the printing device as a byte stream. (With SRM version 1.0, only ASCII files can be used.)

Aborting Plotting In Progress

To abort an in-progress plot, use the SPOOL ABORT command from the SRM server. The system stops sending data to the output device and closes, then purges the file. For details on bringing the spooler UP and DOWN, see

With SRM 2.0, if a plotter is taken off-line while a file is being spooled, the spooler stops and resumes when the plotter is put back on-line. No data is lost during such an interruption. SRM 1.0 also resumes plotting, but from the beginning of the file.

Dumping Graphics to a Printer Spooler

DUMP DEVICE IS allows you to direct graphics generated by DUMP GRAPHICS to a file that can be spooled. For example:

 
100  CREATE BDAT "/PL/Plot_file",1 create file before dump
110  DUMP DEVICE IS "/PL/Plot_file"
120  DUMP GRAPHICS
 

Note that you can only DUMP GRAPHICS to a BDAT or HP-UX file, and you must CREATE the file before making it the dump device. Refer to the HP BASIC Language Reference for more information on CREATE, DUMP DEVICE IS, and DUMP GRAPHICS.

Using a Plotter with BASIC/UX

A multi-user environment does not lend itself to dedicating a plotter to one person. Instead, multi-user systems have a plotter spooler so jobs can share the same plotter without the output from two or more jobs being interleaved. This section explains how to send your output to a plotter spooler device on HP-UX.

Prerequisites

Your HP-UX system should have a spooled plotter connected to it if more than one person will be plotting to the same plotter. If you are the System Administrator, read the chapter "Managing Printers and Printer Output" in the HP-UX System Administration Tasks manual. Since the plotter spooler is set up the same way as a printer spooler, use the same information that you used to set up the printer spooler.

Note that all spooled devices must be accessed through the server on a diskless system, and you cannot have spooled plotters on a diskless node.

Assigning a Plotter Spooler as the Output Device

The output of BASIC/UX commands can be sent as input to HP-UX commands. This feature gives you access to the HP-UX plotter spooler. For example, executing

 
PLOTTER IS "| lp -dplotter_1","HPGL"
 

assigns the destination plotter to be lp -dplotter_1. Note that the vertical bar symbol (|) is a pipe from the BASIC PLOTTER IS command to the HP-UX command lp -dplotter_1. The term pipe means that the output or result of one command is sent as the input to another command. For more information on "pipes", refer to HP BASIC Advanced Programming Techniques. This is the recommended way to assign a plotter from BASIC/UX. However, you can still assign the plotter as follows:

 
PLOTTER IS 705,"HPGL"
 

where 705 is the device selector for a plotter connected to the system.

Sending Graphics Output to the Plotter Spooler

The following program assigns the plotting device to be the HP-UX plotter spooler, positions the plotter pen, draws a rectangle, labels the rectangle, and sets the plotter spooler back to its default value (the CRT).

 
100   PLOTTER IS "| lp -dww_paper","HPGL",6.25,256.25,6.975,186.975 ! Assigns
110                             ! the plotting device and sets the hard
120                             ! clip limits of the plotter in millimeters.
130                             !
140   MOVE 75,45   ! Positions the lower-left hand corner of the rectangle.
150   DRAW 75,70   ! Lines 150 to 180 draw a rectangle.
160   DRAW 122,70
170   DRAW 122,45
180   DRAW 75,45
190   !
200   MOVE 98,58                  ! Sets the initial label position.
210   CSIZE 4                     ! Sets the character size.
220   LABEL "RECTANGLE"           ! Labels the rectangle.
230   !
240   PLOTTER IS CRT,"INTERNAL"   ! Assigns the plotter to be the CRT.
250   END
 

Line 240 in the above program is important because the plotter will not plot your data until SCRATCH A or a new PLOTTER IS statement has been executed. When you execute either of these statements, the pipe is closed and data is sent to the spooler.

Assigning a Window as the Plotting Device

This section covers how BASIC/UX windows can be used as plotting devices. The ability to create windows and send graphics plots to them allows you to display several different graphics plots without erasing them each time you make a new one. To assign a window as a plotting device, execute a command similar to the following:

 
PLOTTER IS 601,"WINDOW"
 

This statement assigns the destination plotter to be window number 601. Note that you must first create window 601 with the CREATE WINDOW command before you can assign it as a plotting device. For information on how to do this, read the section "Using BASIC/UX Window Commands" found in the Using HP BASIC/UX manual.

Sending a Graphics Plot to a BASIC/UX Window

The following program creates BASIC/UX window 601 and assigns it as the plotting device. It next draws a circle in window 601 and re-assigns the plotter to be the CRT or default window 600.

 
100      INTEGER Array(0:5),Xcoord,Ycoord
110      GRAPHICS ON
120      GESCAPE CRT,3;Array(*) ! Assign the hard clip values and row and
130                             ! column information to Array(*).
140      Xcoord=Array(2)        ! Maximum hard clip value in the X axis
150      Ycoord=Array(3)        ! Maximum hard clip value in the Y axis
160      CREATE WINDOW 601,250,350,Xcoord,Ycoord;LABEL "Window Dump" ! Create
170                             ! a window the size of default window 600.
180      PLOTTER IS 601,"WINDOW" ! Assign window 601 as the plotter.
190                             !
200      MOVE 75,45             ! Position the circle.
210      POLYGON 20,40,40,FILL  ! Draw a circle.
220      PLOTTER IS CRT,"INTERNAL" ! The plotter is the CRT.
230      END