Publishing graphics generated with TAMS BASIC for Linux

 

The Red Hat Linux environment brings the ability to support a large variety of available printers. These printers can be directly attached to the Linux system, or networked. And by using Samba, you can share existing Windows printers already residing on your network.


We have been asked for tips in using these printers to produce hardcopy output of graphics that were generated in BASIC for Linux.   Related questions have also arisen, such as whether BASIC for Linux can generate graphics files with portable formats, such as TIFF, JPG, PNG, and EPS.


One answer to all of these questions involves the use of a GNU software program, hp2xx. It is able to read a file that contains HPGL commands, and then translate the information into a file of another type.  The program hp2xx does not come with Red Hat Linux, but it is avaiable for free (unsupported), and is capable of interpreting a large subset of HPGL commands. It allows for many options in the format of the finished output file.  If you use EPS, you can have color output on color printers.  hp2xx allows for many options, such as  rotating 90 degrees before converting.  This allows for "landscape" orientation, normally more convenient for use with graphics that are displayed in BASIC. We have been pleased with the results.


You can read about and obtain the hp2xx software at http://www.gnu.org/software/hp2xx

We downloaded the product and used the makefile to build the binaries on our system, without any trouble. Once the hp2xx

Trying it out is easy - let's say we have a file plotted with HPGL called PLOTFILE. We want to quickly view it as a .jpg file since we can see that with any browser.


hp2xx -m jpg PLOTFILE


After executing that command, a new file, PLOTFILE.jpg, is available and can be viewed with any browser or graphics viewer.


Hardcopy

For hardcopy, we first made sure that we were able to use lpr on our Linux machine before we attempted to output from BASIC. The graphical tool, /etc/printtool, was quite useful. It is nice to be able to print test pages, and use Linux exclusively to get printing working. Once that is accomplished, the printing task from BASIC can be attempted.


Many times, all you want is a hard copy printout of the same thing that you can generate on the screen, and you want it printed in landscape mode.  This is done by plotting to a file, and then transforming that file into one that can be handled by the lpr. All of this can be done without leaving BASIC by using the EXECUTE command.


Here are some relevant code fragments:


(The file for the PLOTTER IS file must exist and must be of type HPUX or BDAT. The touch command in Linux was used because it will create the file if none exists and not complain if it already does exist.)

50   Make_hard_copy=1

60   !... execution continues


320   IF Make_hard_copy THEN

330      EXECUTE ("touch PLOTFILE")

340      PLOTTER IS "PLOTFILE","HPGL"

350   ELSE

360      PLOTTER IS CRT, "INTERNAL"

370   END IF

380   !  generate graphics

390   !  ... and so on


After all the drawing is completed, we need to close the file, convert it, and print it. The file is closed by a subsequent PLOTTER IS statement, and the hp2xx utility is used to translate, rotate 90 degrees, and set the pen width to 3 pixels in this case. Line 1440 creates a file called PLOTFILE.eps which is then printed by line 1450.

1400  Finishplot: !

1430  PLOTTER IS CRT,"INTERNAL"

1440  EXECUTE ("hp2xx -r90 -p3 -m eps PLOTFILE")

1450 EXECUTE ("lpr PLOTFILE.eps")


Redhat Linux comes with Imagemagick and if you installed that, you can use the display command to preview your work. If you do, know that the display window will have to be closed before BASIC will continue executing.

1445 EXECUTE ("display PLOTFILE.eps")


The hp2xx command normally generats diagnostic output in the calling window. You may want to change it to direct this output to a log file with the -l switch, or simply turn it off with -q once you have it working:

changed to:

1440 EXECUTE ("hp2xx -q -r90 -p3 -m eps PLOTFILE")


Here is an example of a file created with BASIC, and translated from an HPGL Plotter file into a .jpg for use in a web page:



To view the BASIC program that generated the graphics, click here