10 : REM
20 : REM  CGP-115 PLOTTER PROGRAM
30 : REM  BOB SCOTT SILICON VALLEY CHAPTER, FOG
40 : REM
50 : REM   PROGRAM WILL ACCEPT UP TO 100 DATA POINTS
60 : REM   PER CURVE. NO LIMIT ON NUMBER OF LINES PER PLOT
70 : REM   ENTER DATA WITH X-Y MAX AS FIRST CURVE AS IT
80 : REM   DETERMINES THE PLOT SCALE
90 : REM
100 : REM   
110 : OPTION BASE 1 : DIM D(50,2) : DEFINT I-N
120 : PRINT CHR$(26);"PRESS RETURN WHEN PLOTTER CONNECTED"
130 : PRINT "TO SERIAL PORT"
140 : INPUT WT$:ISECOND=0
150 : POKE 3,64
160 : REM
170 : REM SERIAL PORT NOW SET AS LIST DEVICE
180 : REM
190 : XOFF=0 : YOFF=0
200 : PRINT CHR$(26);"PLEASE INPUT THE FOLLOWING:"
210 : PRINT:PRINT
220 : LINE INPUT "TITLE ",TI$
230 : LINE INPUT "HORIZONTAL AXIS LABEL ",HT$
240 : LINE INPUT "VERTICAL AXIS LABEL ",VT$
250 : PRINT CHR$(26)
260 : PRINT "PLEASE ANSWER THE FOLLOWING:"
270 : PRINT :PRINT
280 : INPUT "X-AXIS UPPER LIMIT ";XMAX
290 : INPUT "X-AXIS LOWER LIMIT ";XMIN
300 : INPUT "Y-AXIS UPPER LIMIT ";YMAX
310 : INPUT "Y-AXIS LOWER LIMIT ";YMIN
320 : INPUT "(E)DGE (Z)ERO-CENTER SCALE ";AN$
330 : IF AN$="E" THEN IEDGE=1 ELSE IEDGE=0
340 : INPUT "(L)INE OR (P)OINT PLOT ";AN$
350 : IF AN$="L" THEN LPLOT=1 ELSE LPLOT=0
360 : INPUT "NUMBER OF DATA POINTS (50 MAX) ";NPOINT
370 : IF NPOINT>50 THEN NPOINT=50
380 : PRINT CHR$(26)
390 : PRINT "SELECT PLOT COLOR:"  
400 : PRINT " 0 - BLACK"
410 : PRINT " 1 - BLUE "
420 : PRINT " 2 - GREEN"
430 : PRINT " 3 - RED  "
440 : INPUT IPEN  
450 : PRINT:PRINT
460 : INPUT "LINE TYPE (0-15)"; ILINE
470 : REM            
480 : REM
490 : REM  	ALL USER PARAMETERS INPUT
500 : REM	NOW GET THE DATA
510 : REM
520 : REM
530 : PRINT CHR$(26)
540 : INPUT "ENTER DATA FROM KEYBOARD? ";AN$
550 : IF AN$<>"N" THEN GOTO 630
560 : INPUT "DATA FILE NAME? ";FI$
570 : OPEN "I",1,FI$
580 : FOR I=1 TO NPOINT
590 : IF EOF(1) THEN NPOINT=I-1: GOTO 680
600 :     INPUT #1, D(I,1),D(I,2)
610 :    NEXT I
620 : GOTO 680
630 : PRINT "INPUT DATA IN X,Y ORDER, SEPARATED BY A COMMA"
640 : FOR I=1 TO NPOINT
650 :      PRINT "DATA POINT ";I;
660 :      INPUT D (I,1),D (I,2)
670 : NEXT I
680 : PRINT CHR$(7);CHR$(26):IF ISECOND THEN GOTO 1440
690 : PRINT "PLOTTING....PLEASE WAIT"
700 : LPRINT:LPRINT
710 : LPRINT:LPRINT
720 : K=(40-LEN(TI$))/2          'SET UP SPACES
730 : LPRINT SPACE$(K);LEFT$(TI$,40)     'PRINT CENTERED TITLE
740 : LPRINT CHR$(18)          'TOGGLE TO GRAPHICS MODE
750 : LPRINT "R0,-450"
760 : LPRINT "R20,0"           'LEFT MARGIN FOR Y-AXIS LABEL
770 : LPRINT "I"               'SET ORIGIN HERE
780 : LPRINT "Q3"              'SET VERTICAL PRINT
790 : LPRINT "H"
800 : K=(40-LEN(VT$))/2
810 : LPRINT "P";SPACE$(K);VT$           'PRINT Y-AXIS LABEL
820 : LPRINT "H"
830 : LPRINT "Q0"              'SET HORIZONTAL PRT
840 : LPRINT "M-10,-40"
850 : K=(40-LEN(HT$))/2 
860 : LPRINT "P";SPACE$(K);LEFT$(HT$,40)  'PRINT X-AXIS LABEL
870 : LPRINT "H"
880 : PRINT "COMPUTING SCALING FACTORS"
890 : REM
900 : REM
910 : XSCALE=460/ABS(XMAX-XMIN)
920 : YSCALE=460/ABS(YMAX-YMIN)
930 : REM 
940 : REM     DRAW COORDINATE AXIS REQUESTED
950 : REM     
960 : REM     ZERO CENTER AXIS
970 : REM
980 : IF IEDGE OR XMIN>0 AND YMIN>0 THEN GOTO 1210
990 : LPRINT "M";ABS(XMIN)*XSCALE;",0"
1000 : LPRINT "X0,46,10"
1010 : LPRINT "M0,";ABS(YMIN)*YSCALE
1020 : LPRINT "X1,46,10"
1030 : LPRINT "H"
1040 : LPRINT "X0,460,1"
1050 : LPRINT "H"
1060 : LPRINT "X1,460,1"
1070 : LPRINT "M";ABS(XMIN)*XSCALE+5;",0"
1080 : LPRINT "S0"
1090 : FOR I=0 TO 10
1100 :      LPRINT "P";YMIN+(YMAX-YMIN)/10*I
1110 :      LPRINT "M";ABS(XMIN)*XSCALE+5;",";46*(I+1)
1120 : NEXT I
1130 : LPRINT "M0,";ABS(YMIN)*YSCALE-10
1140 : FOR I=0 TO 10 
1150 :      LPRINT "P";XMIN+(XMAX-XMIN)/10*I
1160 :      LPRINT "M";46*(I+1)-15;",";ABS(YMIN)*YSCALE-10
1170 : NEXT I
1180 : XOFF=-XMIN*XSCALE
1190 : YOFF=-YMIN*YSCALE
1200 : GOTO 1430
1210 : REM
1220 : REM      EDGE AXIS 
1230 : REM
1240 : LPRINT "X0,46,10"
1250 : LPRINT "H"
1260 : LPRINT "X1,46,10"
1270 : LPRINT "H"
1280 : LPRINT "M5,0"
1290 : LPRINT "S0"
1300 : FOR I=0 TO 10
1310 :      LPRINT "P";YMIN+(YMAX-YMIN)/10*I
1320 :      LPRINT "M5,";46*(I+1)
1330 : NEXT I
1340 : LPRINT "H"
1350 : LPRINT "M-10,-20"
1360 : FOR I=0 TO 10
1370 :      LPRINT "P";XMIN+(XMAX-XMIN)/10*I
1380 :      LPRINT "M";46*(I+1)-10;",-20"
1390 : NEXT I
1400 : XOFF=-XMIN*XSCALE
1410 : YOFF=-YMIN*YSCALE
1420 : REM
1430 : REM   NOW READY TO PLOT DATA POINTS AS SPECIFIED
1440 : REM
1450 : LPRINT "C";IPEN
1460 : CLOSE
1470 : LPRINT "L";ILINE
1480 : LPRINT "M";D(1,1)*XSCALE+XOFF;",";D(1,2)*YSCALE+YOFF
1490 : LPRINT "S1"
1500 :  IF LPLOT <> 1  THEN LPRINT "P*"
1510 : FOR I=2 TO NPOINT
1520 :      XX=D(I,1)*XSCALE+XOFF
1530 :      YY=D(I,2)*YSCALE+YOFF
1540 :      IF LPLOT THEN LPRINT "D";XX;",";YY :GOTO 1560
1550 :      LPRINT "M";XX;",";YY : LPRINT "P*" 
1560 : NEXT I
1570 : LPRINT "H"
1580 : REM
1590 : REM    CHECK FOR MORE DATA
1600 : REM
1610 : PRINT CHR$(26):ISECOND=1
1620 : INPUT "ANOTHER CURVE ON THIS PLOT? (Y/N)"; AN$
1630 : IF AN$="Y" THEN GOTO 340
1640 : INPUT "OVERLAY A REFERENCE GRID? (Y/N)";AN$
1650 : IF AN$<>"Y" THEN GOTO 1820
1660 : INPUT "GRID DENSITY? (1-40, 10 NORMAL)";IGRID
1670 : INPUT "GRID LINE TYPE (0-15)";IGLIN
1680 : LPRINT "L";IGLIN:LPRINT "C0"
1690 : LPRINT "H":IDIR=1
1700 : FOR I=1 TO IGRID
1710 :   LPRINT "R";460/IGRID;",0"
1720 :   LPRINT "J0,";465*IDIR
1730 :   IDIR=IDIR*-1
1740 : NEXT I
1750 : LPRINT "H":IDIR=1
1760 : FOR I=1 TO IGRID
1770 :   LPRINT "R0,";460/IGRID
1780 :   LPRINT "J";465*IDIR;",0"
1790 :   IDIR=IDIR*-1
1800 : NEXT I
1810 : LPRINT "L";ILINE
1820 : REM
1830 : REM    PRINT FINAL DATA
1840 : REM
1850 : LPRINT "S1"         'LARGE LETTERS
1860 : LPRINT "M0,-50"     'KICK OUT SOME PAPER
1870 : LPRINT "A"          'OUT OF GRAPHICS MODE
1880 : REM
1890 : REM       GET USER LINE LABELS
1900 : REM   
1910 : INPUT "FURTHER LABELING ? (Y/N)"; AN$
1920 : IF AN$="N" THEN GOTO 2090
1930 : PRINT CHR$(26)
1940 : PRINT "SELECT COLOR"
1950 : PRINT "   0 BLACK"
1960 : PRINT "   1 BLUE "
1970 : PRINT "   2 GREEN"
1980 : PRINT "   3 RED  "
1990 : PRINT :PRINT
2000 : INPUT IPEN
2010 : LPRINT CHR$(18)
2020 : LPRINT "C";IPEN
2030 : LPRINT "A";
2040 : INPUT "INPUT LABEL";LA$
2050 : K=(40-LEN(LA$))/2
2060 : LPRINT SPACE$(K);LEFT$(LA$,40)
2070 : GOTO 1910
2080 : REM 
2090 : REM   CLOSE OUT
2100 : REM  
2110 : LPRINT CHR$(18)
2120 : LPRINT "C0"
2130 : LPRINT "A"
2140 : POKE 3,128
2150 : END
: REM   CLOSE OUT
2100 : REM  
2110 : LPRINT CHR$(18)
2120 : LPRINT "C0"
2130 : LPRINT "A