Google
 

Trailing-Edge - PDP-10 Archives - decus_20tap4_198111 - decus/20-0126/apbas.rno
There is 1 other file named apbas.rno in the archive. Click here to see a list.
.ps 63,65;.ap
.ft;.t Programming Note 13
.b 1;.c;^&BASIC_ FORTRAN_ PLOTTING_ SUBROUTINES\&
.b 2;.c;Trevor Williamson
.c;Computer Centre
.c;25-Sep-75
.hl 1 GENERAL
 The subroutines described below manipulate a "pen" which can be moved
about, raised or lowered, to create a line drawing on paper.
Pen movements are made in a straight line from one point to another, 
relative to an origin which can be defined. 
Curves are made up by drawing a number of small straight line segments.
Subpictures can be created by writing a subroutine which redefines the
origin to a given point, draws the subpicture, and restores the original
origin. There are subroutines to aid graph drawing, which will scale
an array of data to fit a given graph size, draw axes, and draw the
points. Other subroutines will draw text messages and magnify a part of
the plot and set and return some parameters like the current pen 
position.
 These functions are primitive operations from which the programmer can
build his own more complicated drawings.
Other FORTRAN callable plotting routines are ATOPLT, which is a simple
method of drawing graphs described in PD25, and others which may be 
found in the Application Software Catalogue.
.hl 2 Plotting Hardware at La Trobe
 The plotter is a Gould electrostatic printer/plotter. It does not 
have a physical pen like an incremental plotter but can operate at high speed
producing medium quality drawings on electrostatic paper. The
plotting software makes the Gould look like an incremental plotter
but allows the user to make use of some special features on the
Gould, such as the ability to erase lines already drawn and to
draw lines of different densities. 
 The plotter paper is 250mm wide and the maximum plot length is about
3m. The plotting software will allow the user to draw plots up to 3m
wide by breaking the plot into a number of strips 250mm wide, which
can be joined by the user to give the full sized plot. Users who 
wish to use this feature should consult the Computer Centre staff
first as it is a marvellous way to waste expensive paper.
 The computer centre is writing routines to enable these basic FORTRAN
subroutines to be used with the Tektronix 4012 terminal. 
This is the subject of a separate note.
.hl 2 Plot Spooling
 Subroutines do not draw directly onto the plotter, but create
disk files which must be queued to the plotter. The files produced by
the plotter subroutines have a random name and extension .PLT.
At logout the KJOB command queues all .PLT files to the plotter, but
the user may queue the files beforehand using the PLOT command (see
User's Handbook), e.g.
.b 2;.c;&.PLOT_ _ _ *.PLT
.hl 2 Units
 All plotting is done in millimeters. This means that if you request, by
a call to some subroutine, a line or pen movement of say W units, the 
actual distance on the paper covered by the line or pen movement will
be W mm. This holds true unless the user specifies a scaling factor 
(or magnification factor) by a call to the subroutine FACTOR.
If a scaling factor of say Z is specified for the X direction on the
paper then a call for a move of W units in the X direction will result
in a move of W*Z mm in the X direction on the paper.
These scaling factors, once set, hold for all lines drawn by any
plotting subroutine. The units specified by the user in a call 
are refered to as USER UNITS, as opposed to the scaled physical
units of movement.
.hl 1 PLOTTING SUBROUTINE CALLS.
 FORTRAN naming conventions are used throughout this document to
indicate whether a variable is REAL or INTEGER. Optional arguments
are indicated by inclusion in '[]' (which are not part of the argument
string) and may be included or omitted at the wish of the user.
 The subroutine calls are similar to a set of calls known as CALCOMP
subroutine calls and widely used as a de facto industry standard.
The differences between the La Trobe calls and CALCOMP calls are
detailed in Appendix D.
.hl 2 Initializing a plot.
 This routine must be called BEFORE any other plotting routine. It 
creates the output file and initializes internal variables.
Failure to call this routine will result in the fatal error message
'PLOT FILE NOT OPEN'.
 The paper sizes specified in this call (PX and PY) are the expected
true size of the plot, that is the physical size of the paper used by
the plot. If this size is exceeded by a plot then the user program
will by stopped and the message
.pg;.b;.nf;.ts 8 
	'X COORDINATE OUT OF BOUNDS'  
or
	'Y COORDINATE OUT OF BOUNDS'
.f;.b;will be printed.
 This subroutine moves the pen to (0.0,0.0) the paper and sets the
scaling factors to 1.0.
.b 2;.nf;.ts 8 16 22 
		CALL PLOTS (PX,PY,IBAK)
.b 1;	PX	X paper size in millimeters
	PY	Y paper size in millimeters
	IBAK	background code
		IBAK	= -1 is black paper with white lines
			=  0 is white paper with black lines
.f;.hl 2 Moving the pen
 This subroutine allows the user to move the pen from its current
position to that specified by the arguments. See 2.5
for details of scaling and 2.3 for details of origin moving, both
of which effect the result of a call to PLOT. The routine also allows
for the pen to be raised, lowered or left as it is before the required 
move is performed.
.b 2;.lm +16
CALL  PLOT (X,Y,IPEN)
.b 1;.i -8;(X,Y)_ _ _ the coordinate (in user units) of
the point to which the pen is to move
.i -8;IPEN_ _ _ _ the code to indicate the state to
which the pen must be set before the
movement
.nf;IPEN = 3 pen up
IPEN = 2 pen down
IPEN = 1 no change
IPEN = 0 erase line
.lm -16;.f;.hl 2 Moving the origin
 All coordinates given are relative to a user defined origin.
The origin is defined to be (0.0,0.0), the left hand
bottom corner of the paper. 
It can be moved by calling PLOT with a negative value for IPEN.
The pen is placed on the new origin.
.b 2;.lm +16
CALL PLOT (X,Y,IPEN)
.b 1;.i -8;(X,Y)_ _ _ the new origin relative to the old origin
.i -8;IPEN_ _ _ _ the code to indicate the state
of the pen before the move to (X,Y)
.nf;IPEN = -3  pen up during move
IPEN = -2  pen down during move
IPEN = -1  no change to pen before move
.lm -16;.f;.hl 2 Closing a Plot.
 Before stopping, a user program must close the plot file.
If this is not done the output may be lost. This is achieved by
a call to PLOT.
.b 2;.lm +16
CALL PLOT (X,Y,999)
.b 1;.i -8;(X,Y)_ _ _ ignored
.i -8;999_ _ _ _ _ indicates that any open plot
file should be closed
.lm -16;.hl 2 Altering the Scaling Factors.
 Sets the scaling (magnification) factors for the plot. 
The factors are multiplicative. For instance if you wish a call for a
movement of M units to correspond to 0.5M millimetres of paper a scaling
factor of 0.5 should be employed: 
.br
i.e. (user units) X (scaling factor) = (millimetre moved).
.b 2;.lm +16
CALL FACTOR (XFACT[,YFACT])
.b;.i -8;XFACT_ _ _ X-scaling factor, and Y scaling factor
unless the YFACT argument is given
.i -8;YFACT_ _ _ Y-scaling factor, if given
.lm -16;.hl 2 Plotting Text
 The subroutine SYMBOL allows a program to plot a string of ASCII 
characters. The string may be located at any point in the plot and be
drawn at any angle to the X direction. The height of the characters
can be specified. The width of the character plus the inter-character
space is equal to the height.
The pen is positioned at the lower left hand
corner of the next character position on return from SYMBOL (see
appendix C for a table of the characters as they are drawn).
.b 2;.lm +16
CALL SYMBOL (X,Y,HEIGHT,TEXT,ANGLE,NCHAR)
.b 1;.i -8;(X,Y)_ _ _ position of lower left hand corner of text
.i -8;HEIGHT_ _ height of characters in user units
.i -8;TEXT_ _ _ _ text to be plotted, either a literal or an 
array
.i -8;ANGLE_ _ _ the angle of the text to the X direction in
degrees, anticlockwise rotation.
.i -8;NCHAR_ _ _ 0_ _ _ a single character, in R1 format, is  
plotted
.br
+N_ _ N is the number of characters, in A5 format,
.br;_ _ _ _ plotted
.ps 65,65;.lm -16;.hl 2 Plotting Special Centering Symbols
 There are a number of symbols available that are not part
of the standard ASCII character set. These symbols are plotted by the
subroutine SYMBOL and are centred on the coordinates given. 
The symbol to be plotted is represented by an integer value in the
calling sequence. Appendix C lists the symbols available and their
corresponding integers.
The pen is left at the centre of the symbol after it is drawn. 
.b 1;.lm +16;.nf 
CALL SYMBOL (X,Y,HEIGHT,INTEG,ANGLE,ICODE)
.b 1;.i -8;(X,Y)_ _ _ centre of the symbol
.i -8;HEIGHT_ _ height of the symbol
.i -8;INTEG_ _ _ integer corresponding to the desired symbol
.i -8;ANGLE_ _ _ angle of symbol to X direction in degrees
.i -8;ICODE_ _ _ -3  pen up for move to (X,Y)
.nf;-2  pen down for move to (X,Y)
.lm -16;.f;.hl 2 Plotting an Axis
 This subroutine draws an axis according to the specifications in the 
call, with ticks every 10 user units, titles and value labels.
The values of the arguments XMIN and DX can best be obtained by calling
the routine SCALE (see section 2.11).
.b 1;.lm +16 
CALL AXIS (X,Y,ASC,NASC,S,THETA,XMIN,DX)
.b 1;.i -8;X_ _ _ _ _ _ _ X coordinate of start of axis
.i -8;Y_ _ _ _ _ _ _ Y coordinate of start of axis
.i -8;ASC_ _ _ _ _ axis label, either literal or array
.i -8;NASC_ _ _ _ number of characters in ASC. If NASC is
positive ticks are on clockwise side of
axis and if negative they are on anticlockwise side
.i -8;S_ _ _ _ _ _ _ length of axis in user units
.i -8;THETA_ _ _ angle of axis to X direction, in degrees
.i -8;XMIN_ _ _ _ value of label to be drawn at the first
tick on the axis
.i -8;DX_ _ _ _ _ _ the amount by which the label drawn at each tick is
incremented per tick
.lm -16;.f;.hl 2 Drawing Lines through Points
 Draws a continuous set of straight line segments between given points.
.b 1;.lm +16
CALL LINE (X,Y,N,K)
.b 1;.i -8;X_ _ _ _ _ _ _ array of X data
.i -8;Y_ _ _ _ _ _ _ array of Y data
.i -8;N_ _ _ _ _ _ _ number of points to be drawn
.i -8;K_ _ _ _ _ _ _ the increment to be used to select 
values from the X and Y array. For
instance if K=2 only every second 
point in the X and Y arrays will
be plotted.
.ps 63,65;.lm -16;.f;.hl 2 Plotting Numbers
 This routine plots a number in FORTRAN F type format except that no
limit is given for the total number of digits in the number.
.b 1;.lm +16
CALL NUMBER (X,Y,SIZE,FNUM,THETA,NDIG)
.B 1;.i -8;X_ _ _ _ _ _ _ X coordinate of start of number (lower
lefthand corner)
.i -8;Y_ _ _ _ _ _ _ Y coordinate of start of number (lower
lefthand corner)
.i -8;SIZE_ _ _ _ size of each digit in user units
.i -8;FNUM_ _ _ _ number to be plotted
.i -8;THETA_ _ _ angle of number to X direction in degrees
.i -8;NDIG_ _ _ _ number of digits to be plotted to right
of decimal point (if negative, the integer part only
is drawn)
.lm -16;.f;.hl 2 Scaling Points for Plotting
 The subroutine SCALE is passed an array of data (X) and the length of the
axis on which the data is to be plotted. SCALE selects 
a suitable minimum value (XMIN) and increment per tick (DX) 
from the array, so that
the data may be plotted on the axis. 
The values of XMIN and DX are returned and should be used in a call to AXIS 
so that the axis drawn fits the data in array X.
These values are chosen in such
a way as to eliminate rounding error from the plotted tick values.
The contents of the array are scaled to allow them to be plotted 
against the axis with a call to LINE.  
SCALE normally changes the contents of the array X.
.b 2;.lm +16
CALL SCALE (X,N,S,XMIN,DX)
.b 1;.i -8;X_ _ _ _ _ _ _ the data array
.i -8;N_ _ _ _ _ _ _ number of elements in X
.i -8;S_ _ _ _ _ _ _ axis length
.i -8;XMIN_ _ _ _ scaled data minimum for use by AXIS
.i -8;DX_ _ _ _ _ _ scaled data increment for use by AXIS
.lm -16;.f;.hl 2 Locating the pen
 Returns the current setting of the variables in the calling sequence.
.b 1;.lm +16
CALL WHERE (X,Y,XFACT[,YFACT])
.b 1;.i -8;(X,Y)_ _ _ pen position in user units relative
to the current origin
.i -8;XFACT_ _ _ current X scaling factor
.i -8;YFACT_ _ _ current Y scaling factor
.lm -16;.hl 2 To change line density
 The plotter is capable of plotting lines of various density.
Every nth point in the line is plotted to
achieve a line density of 1/n.
This setting, which is applied to characters and erases also,
holds until the next call to LINEWT.
.b 1;.nf;.ts 8 16 24
		CALL LINEWT (I)
.b 1;	I	density indicator
		0 or 1	standard
		-n	1/n line density
.b 2;.f
.pg;.hl 1 Examples
.hl 2 Example of use of PLOTS, PLOT, FACTOR and SYMBOL.
 See APPENDIX A for output.
.b 2;.nf
C	   INITIALIZE THE PLOT
C
	CALL PLOTS(450.0,250.0,0)
C
C	   REDEFINE THE ORIGIN
C
	CALL PLOT(220.,130.,-3)
C
C	   SET THE SCALING FACTORS
C	   FOR X 1 UNIT = 50. MM
C	   FOR Y 1 UNIT = 50. MM
C
	CALL FACTOR(50.,50.)
C
C	   NOW DRAW A BOX WITH SYMBOLS AT THE
C	   CORNERS.
C
	CALL PLOT(-1.,1.,3)
	CALL PLOT(-1.,-1.,2)
	CALL PLOT(1.,-1.,2)
	CALL PLOT(1.,1.,2)
	CALL PLOT(-1.,1.,2)
C
C	   NOW TO DRAW THE SYMBOLS 2.0 MM TO THE RIGHT OF
C	   AND ABOVE EACH CORNER.
C
	CALL SYMBOL(-.96,1.04,0.06,'A',0.0,1)
	CALL SYMBOL(-.96,-.96,0.06,'B',0.0,1)
	CALL SYMBOL(1.04,-.96,0.06,'C',0.0,1)
	CALL SYMBOL(1.04,1.04,0.06,'D',0.0,1)
C
C	   CLOSE THE PLOT FILE
C
	CALL PLOT(0.,0.,999)
	STOP
	END
.pg;.b 2;.f
.pg;.hl 2 Use of SCALE, AXIS and LINE.
 See APPENDIX B for output.
.b 2;.nf
	DIMENSION X(20),Y(20)
	DATA X /1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,
	113.,14.,15.,16.,17.,18.,19.,20./
	DATA Y /.01,.02,.03,.04,.05,.06,.07,.08,.09,.1,
	1.09,.08,.07,.06,.05,.04,.03,.02,.01,.00/
C
C	   INITIALIZE THE PLOTTING SOFTWARE
C
	CALL PLOTS(250.,250.,0)
C
C	   SCALE THE X DATA
C
	CALL SCALE(X,20,150.,XMIN,DX)
C
C	   SCALE THE Y DATA
C
	CALL SCALE(Y,20,150.,YMIN,DY)
C
C	   DRAW THE X AXIS
C
	CALL AXIS(30.0,30.0,'X AXIS',-6,150.,0.0,XMIN,DX)
C
C	   DRAW THE Y AXIS
C
	CALL AXIS(30.0,30.0,'Y AXIS',6,150.,90.0,YMIN,DY)
C
C	   SET THE ORIGIN TO WHERE THE AXIS CROSS
C
	CALL PLOT(30.,30.,-3)
C
C	   PLOT THE DATA
C
	CALL LINE(X,Y,20,1)
C
C          CLOSE THE PLOT FILE
C
	CALL PLOT(0.,0.,999)
	STOP
	END
.f;.pg;.b 2;.c;APPENDIX A
.b 1;.c;^&Plot_ Produced_ by_ Example_ 1.\&
.pg;.b 2;.c;APPENDIX B
.b 1;.c;^&Plot_ Produced_ by_ Example_ 2.\&
.pg;.b 2;.c;APPENDIX C
.b 1;.c;^&Symbols\&
.pg;.b 2;.c;APPENDIX D
.b 1;.c;^&Converting_ CALCOMP_ Calls_ to_ La_ Trobe.\&
 This section explains how to modify a program using CALCOMP 
Plotting Subroutines to work at La Trobe. Full details of the CALCOMP
software is available in 'PROGRAMMING CALCOMP PEN PLOTTERS' which may
be borrowed from the reception desk of the computer centre.
.ls;.le;PLOTS
 Calls to this routine are plotter dependent and must be replaced.
Simply replace the CALCOMP call with a suitable La Trobe call.
.le;PLOT
 No changes are needed to calls to PLOT.
.le;FACTOR
 No changes are needed to calls to FACTOR.
.le;WHERE
 No changes are needed to calls to WHERE.
.le;AXIS
 No changes are needed to calls to AXIS.
.le;NEWPEN
 This subroutine has no exact equivalent on the La Trobe system. 
Similar effects can sometimes be obtained by varying the line weight
(CALL LINEWT) on the La Trobe plotter. Therefore a user may remove calls 
to NEWPEN or replace them with suitable calls to LINEWT.
.le;SYMBOL
 The only differences between the CALCOMP and La Trobe SYMBOL 
subroutines occur in the call to draw centred symbols. The CALCOMP
call uses -1 for pen up in move to (X,Y) and -2 for pen down.
Change -1 in the CALCOMP call to -3 and the two routines will perform
the same function.
 The La Trobe SYMBOL routine does not have the
continuation
feature. That is, if the call has 999.0 for the X and Y arguments
then the text will be continued after the last text drawn.
The following example will show how to simulate this effect at La Trobe.
.pg;.b 2;.nf;.ts 2 6 9
.lm +8;.i -8
CALCOMP:
.b 1;CALL SYMBOL (10.0,20.0,3.0,'EXAMP',0.0,5)
_ .
_ .
_ .
CALL SYMBOL (999.0,999.0,3.0,'LE',0.0,2)
_ .
_ .
_ etc
.B 2;.i -8;La Trobe:
.b 1;CALL SYMBOL (10.0,20.0, 3.0,'EXAMP',0.0,5)
CALL WHERE  (SX,SY,FACT)
_ .
_ .
_ .
CALL SYMBOL (SX,SY,3.0,'LE',0.0,2)
.f;.lm -8;.le;NUMBER
 No changes are required to the calls to NUMBER, but the
result may be slightly different. In the CALCOMP call the
number-of-digits argument equal to -n means truncate n digits from
the right of the number. At La Trobe it means the same as -1, that
is draw the integer part of the number only.
.le;SCALE
 In the CALCOMP call the order and number of the arguments is
different. The second and third arguments are reversed and the increment
is not available at LaTrobe.
 For the
CALCOMP call the values of XMIN and DX are returned in the data array,
so that
the data array must be two elements longer than
the number of data elements in it. It is necessary to modify
CALCOMP calls to include XMIN and DX in the arguement list and to use 
these values later, e.g. in calls to AXIS.
 Other more serious difficulties may arise as a result of the
following 
.ls;.le;The La Trobe call does not allow the user to specify an increment
for the arrays (so that only every nth element is used). This may
result in the need to copy the data to be scaled into a seperate array
before calling SCALE.
.le;The sign of INC in the CALCOMP call indicates whether XMIN is to be
a maximum or a minimum and DX negative or positive respectively.
This feature does not exist in the La Trobe system.
.pg;.els;.b 1;.lm +8
.i -8;The CALCOMP call:
.b 1;CALL SCALE (X,AXLEN,N,INC)
.b 1;.i -8;X_ _ _ _ _ _ _ data array, where X is 2 elements longer than the length of the data
.i -8;AXLEN_ _ _ axis length
.i -8;N_ _ _ _ _ _ _ size of X
.i -8;INC_ _ _ _ _ increment to be used when choosing
elements of X that is if INC = 2 only
select every second element of X
.b 2;.i -8;EXAMPLES
.b 2;.i -8;CALCOMP:
.nf;.B 1;DIMENSION X(202)
CALL SCALE (X,200.0,100,2)
CALL AXIS (50.0,50.0,'CALCOMP',7,200.0,
.i -2;.ts 25;*	10.0,X(201),X(203))
.b 2;.i -6;La Trobe:
.B 1;DIMENSION X(200),XI(100)
.i -8;C
.i -8;C_ _ _ _ _ _ _ COPY REQUIRED DATA INTO AN ARRAY
.i -8;C
DO 10 I = 1,100
.i -8;10_ _ _ _ _ _ X1(I) = X(2I-1)
CALL SCALE (X1,100,200.0,XMIN,DX)
CALL AXIS (50.0,50.0,'LA TROBE',8,200.0,XMIN,DX)
.lm -8;.b 2;.f
.le;LINE
 The CALCOMP call to LINE allows the drawing of symbols at the points
being plotted, optionaly joined by straight line segments.
These features are not available with the La Trobe LINE routine and
must be programmed (see examples below).
.pg;.lm +8 
.i -8;The CALCOMP call is:
.b 3;CALL LINE (X,Y,N,INC,LTYP,INT)
.b 1;.i -8;X _& Y_ _ _ data arrays
.i -8;N_ _ _ _ _ _ _ number of points to be plotted
.i -8;INC_ _ _ _ _ the increment in the array
between points to be plotted
.i -8;LTYP_ _ _ _ magnitude of LTYP determines the frequency of plotted symbols
i.e. if LTYP = 4 the symbol specified by INT is drawn at every 4th data point;
if LTYP = 0 points are connected by straight line segments and no 
symbols are drawn; if LTYP > 0 straight lines connect every data point; if
LTYP < 0 no connecting lines are drawn
.i -8;INT_ _ _ _ _ integer specifying the 
centering symbol to be drawn at the
points
.lm -8;.p;To replace a call to the CALCOMP LINE routine the following will
be necessary.
 (a) if LTYP = 0
include the La Trobe call to LINE
.nf;.ts 17;.b;	CALL LINE (X,Y,N,INC)
.f; (b) if LTYP  >_ 0
replace the CALCOMP call with the following code
.b 2;.lm +8 
.nf;J = 0
CALL PLOT (X(1),Y(1),3)
DO 10 I=1,N,INC
J = J + 1
IF(MOD(J,LTYP).NE.1) CALL PLOT(X(I),Y(I),2)
IF(MOD(J,LTYP).EQ.1) 
.i +6;CALL SYMBOL(X(I),Y(I),XIZE,INT,0.0,-2)
.i -8;10_ _ _ _ _ _ CONTINUE
.lm -8;.b 2;.f
 (c) if LTYP <_ 0
replace the CALCOMP call with the following code
.nf;.b 2;.lm +8 
J = 0
DO 10 I=1,N,INC
J = J + 1
IF(MOD(J,LTYP).NE.1) GO TO 10
CALL SYMBOL (X(I),Y(I),SIZE,INT,0.0,-3)
.i -8;10_ _ _ _ _ _ CONTINUE
.lm -8;.f;.els
.b 2;.f
.b 2;.f