
The ECN No Name Newsletter is no longer being published. This is an archived issue.
[previous article] [next article]Have you ever wanted to create plot(5) files from within a program using the CRC plotting routines? If so, you may be happy to hear about a small change we made to the CRC plotting routines. If not, read on and maybe I can convince you that storing graphics in plot(5) files is the way to go. Plot(5) files are just a device independent way of describing the plotting operations that will make a picture. The advantage of storing graphics in plot(5) format is that you only have to run your program once to generate the plot(5) file. Then from the one plot(5) file you can make graphic images on many different devices.
For instance you can run a plot(5) file through the filter "plot -T4014 plotfile" to view the graphic image on a tektronix terminal, or a sun window emulating a tektronix terminal. Then if it looks good, you can send it right to a Printronix or LaserWriter with the command "lpr -Pxx -g plotfile". The -g tells lpr that you are sending plot(5) output to the graphics printer xx. Lpr will find the right filter to make your plot(5) output into the commands needed for that graphics printer. Then if you like the plot and you want to incorporate it into your troff document you could send the plotfile through "plot - Tpic plotfile > picfile" and make pic output. The pic output can then be incorporated into a troff document. See ECN #330 DWB Users Guide for more information on pic.
You can create plot(5) files from within FORTRAN or C programs. For example, it can be done in a FORTRAN program in the following way:
program plot1
plots(5,0,"plotfile")
c put your normal plotting routines here
plot(0.0,0.0,999)
stop
end
If you want to plot to standard output, like the previous default, you have to make sure the third argument to plots is NULL. In the past people have left the third argument off of the plots() call. This happens to work on the machines we have now, but it is not good practice! The best way to do this is to make the third argument "".
program plot2
c prints plot(5) files output to standard output
plots(5,0,"")
c put your normal plotting routines here
plot(0.0,0.0,999)
stop
end
Below is an example that lets you create several plot(5) files from within one FORTRAN program.
program plot3
c program prompts for an output file name
c then opens that file and plots into it
character*256 plotfile
integer i
120 print *, 'if file name is end program
$will exit'
print *, 'input file name for this plot:'
read *, plotfile
c FORTRAN pads the rest of variable plotfile with
c blanks, so we will search through for the first
c blank and put in a NULL character ( '\0' ) to
c tell plots that we only want to use the file name
c up to the first blank. This way we won't create
c a file name with blanks in it.
i=1
100 if (i.le.256 .and. plotfile(i:i).ne.' ')
$then
i = i + 1
goto 100
end if
plotfile(i:i) = '\0'
c Check if the file name given is 'end'. If so, exit.
if (plotfile(1:3) .eq. 'end') call exit(-1)
c Call plots to open plotfile & setup for routines.
call plots(5,0,plotfile)
c put your normal plotting routines here
c call plot to close this plotting file
call plot(0.0,0.0,999)
c go back to the beginning
goto 120
stop
end
When plots(5,0,"plotfile") is called the system tries to open plotfile in what is called append mode. This means that if the file already exists, it is opened and new plotting commands will be added to the end of the file. If a file does not exist, it is created. This is a handy feature if you want to put a series of plots in the same file. To start a new file each time, remove the old plotfile before running your program.
For more information on the CRC plotting routines, type "man crc" on an ECN machine or purchase ECN manual #731 The CRC Plotting Package with Qplot Tutorial at the armory bookstore.