home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / graphics / basplot.lbr / PLOT01.BZS / PLOT01.BAS
Encoding:
BASIC Source File  |  1991-06-25  |  22.5 KB  |  305 lines

  1. '                           <<<   PLOT01.BAS   >>>
  2.  
  3. ' Program to plot on the GDC512 or Microangelo graphics screens the data entered and function calculated by the
  4. ' complimentary program PLOT.BAS.  Program written by J. V. Brancik of Univ. N. S. W.
  5.  
  6. ' Dimensions (X%()=abs.lims. of screen; G%()=info flgs; XD(),YD()=exptl. data; X,Y=fnc.points; DX(),DY()=ranges;
  7. DIM X%(4),G%(12),XD(7,40),YD(7,40),X(400),Y(7,400),DX(7),DY(7),LIM(7,9):' (LIM()=limits)
  8.  
  9. ' Equates (margins left, right, bottom and top, respectively, and format string)
  10. X%(0)=61:X%(1)=471:X%(2)=48:X%(3)=458:L$="####":' coordinates of the default plotting area in abs. units, format
  11. STATP%=241:DATP%=240:' status and data ports for the graphics card
  12.  
  13. GOTO 6000:' where the Main section of this program is and from where all the subroutines are called.  Watch for the
  14. '           selection of PAGE DISPLAY and PAGE EDIT - if your system does not support pages then comment out the
  15. '           line which sets the DISPLAY and EDIT to the PAGE ONE.
  16.  
  17.  
  18. '                             Subroutine section
  19. '                             ==================
  20.  
  21. '    Subroutine to cause delay (graphics screen refresh time - needed only when drawing frames around the screen)
  22. '    Check your system, perhaps you will not need it.  My system has 3 graphics cards are from SME Systems (company you
  23. '    never heard of) connected together with color mixing card giving altogether 6 pages of graphics, each page 512X490
  24. '    pixels - and the delay is needed because somehow the handshake is not perfect.  Some of the codes are the same
  25. '    as for the Microangelo graphics card and only those are used here.  So NO color or page swapping or animation
  26. '    or other gimmics are used here.
  27. 1000 FOR delay=1 TO 500:NEXT:return:' needed only for drawing frames, this is for 6MHz CPU, change to suit
  28.  
  29. '           Subroutines to handle the screen editing functions
  30. '           --------------------------------------------------
  31. ' Codes are for the Televideo terminal
  32. 1100 PRINT CHR$(27)CHR$(42):RETURN:' clear the whole screen
  33. 1110 GOSUB 1130:PRINT CHR$(27)CHR$(89):GOSUB 1130:RETURN:' clear to the end of screen from the current cursot position
  34. 1120 GOSUB 1130:PRINT CHR$(27)CHR$(84):GOSUB 1130:RETURN:' clear to the end of line from the current cursot position
  35. 1130 PRINT CHR$(27)CHR$(61)CHR$(M%+31)CHR$(N%+31);:RETURN:' direct cursor address (set the cursor position)
  36.  
  37.  
  38. '               Subroutines to handle the data files and data
  39. '               ---------------------------------------------
  40.  
  41. '    Subroutine to open a data file for random access, F$=filename, FL%=rec length
  42. 1500 OPEN"R",#1,F$,FL%:FIELD#1,FL% AS R$:RETURN
  43.  
  44. '    Subroutine to read experimental points from the data file (always the default filename PLOT.$$$)
  45. '    xd(i,j) is the x-value of i-th set and j-th pair, yd(i,j) is the y-value of i-th set and j-th pair
  46. 1510 FOR I%=0 TO G%(3)-1:K%=I%*80:FOR J%=1 TO G%(4+I%):GET#1,2*J%-1+K%:XD(I%,J%)=CVS(R$):GET#1,2*J%+K%
  47.      YD(I%,J%)=CVS(R$):NEXT:NEXT:CLOSE:RETURN:' always room for 40 pairs of data per each set
  48.  
  49. '    Subroutine to read points for the function to be plotted
  50. '    x(j) is the x-coordinate of the j-th function point and y(i,j) is the y-coordinate of the j-th function point be-
  51. '    longing to the i-th set (of data)
  52. 1520 FOR J%=1 TO 400:GET#1,J%:X(J%)=CVS(R$):NEXT:FOR I%=1 TO G%(3):FOR J%=1 TO 400:K%=J%+400*I%:_
  53.      GET#1,K%:Y(I%-1,J%)=CVS(R$):NEXT:NEXT:CLOSE:RETURN:' x's are the same for all f(x)'s
  54.  
  55. '    Subroutine to read data for the graphics screen setup
  56. '    lim(set no.,0) = x-coord of axis intersection    lim(set no.,1) = y-coord of axis intersection
  57. '    lim(set no.,2) = X(min)                          lim(set no.,3) = X(max)
  58. '    lim(set no.,4) = Y(min)                          lim(set no.,5) = Y(max)
  59. '    lim(set no.,6) = number of x-axis divisions      lim(set no.,7) = number of y-axis divisions
  60. '    lim(set no.,8) = function minimum                lim(set no.,9) = function maximum
  61. '    lim(set no.,10) = x-tick % above x-axis          lim(set no.,11) = x-tick % below x-axis
  62. '    lim(set no.,12) = y-tick % right of y-axis       lim(set no.,13) = y-tick % left of y-axis
  63. '    here we read only up to lim(set no.,9) - there is no need play with axis ticks
  64. 1530 M%=22:N%=1:GOSUB 1110:INPUT"Type K to use keyboard, D data file for graphics screen setup:",A$
  65.      IF A$="K" THEN RETURN ELSE IF A$="D" THEN 1535 ELSE 1530
  66. 1535 GOSUB 1110:LINE INPUT"Filename is ",F1$:IF F1$="" THEN F$="PLOT0"+MID$(STR$(G%(1)),2,1)+".SET" ELSE F$=F1$
  67.      FL%=40:GOSUB 1500:FOR I%=0 TO 7:GET#1,I%+1:Q$=R$:FOR J%=0 TO 9:' we read lims for all 8 sets regardless
  68.      LIM(I%,J%)=CVS(MID$(Q$,1+4*J%,4)):NEXT:NEXT:CLOSE:RETURN
  69.  
  70. '    Subroutine to write data for the graphics screen set-up into a file
  71. '    (for explanation look on subroutine 1530)
  72. 1540 M%=22:N%=1:GOSUB 1110:LINE INPUT"Filename is ",F1$:IF F1$="" THEN F$="PLOT0"+MID$(STR$(G%(1)),2,1)+".SET" ELSE F$=F1$
  73.      FL%=40:GOSUB 1500:FOR I%=0 TO 7:Q$="":FOR J%=0 TO 9:' we write data for all 8 sets regardless
  74.      Q$=Q$+MKS$(LIM(I%,J%)):NEXT:LSET R$=Q$:PUT#1,I%+1:NEXT:CLOSE:RETURN
  75.  
  76. '    Subroutine to calculate minima and maxima of experimental points (to determine upper and lower limits)
  77. '    this is just for user's information when deciding about the plotting limits
  78. 1600 FOR I%=0 TO G%(3)-1:LIM(I%,2)=XD(I%,1):LIM(I%,3)=XD(I%,1):LIM(I%,4)=YD(I%,1):LIM(I%,5)=YD(I%,1):' for all sets
  79.      FOR J%=1 TO G%(4+I%):' in each set
  80.      IF XD(I%,J%)<=LIM(I%,2) THEN LIM(I%,2)=XD(I%,J%) ELSE IF XD(I%,J%)>=LIM(I%,3) THEN LIM(I%,3)=XD(I%,J%):' min
  81.      IF YD(I%,J%)<=LIM(I%,4) THEN LIM(I%,4)=YD(I%,J%) ELSE IF YD(I%,J%)>=LIM(I%,5) THEN LIM(I%,5)=YD(I%,J%):' max
  82.      NEXT:DX(I%)=LIM(I%,3)-LIM(I%,2):DY(I%)=LIM(I%,5)-LIM(I%,4):NEXT:RETURN
  83.  
  84. '    Subroutine to calculate minima and maxima of functions (lim(i,8)=f(min), lim(i,9)=f(max))
  85. '    this is just for user's information when deciding about the plotting limits
  86. 1610 FOR I%=1 TO G%(3):LIM(I%-1,8)=Y(I%-1,1):LIM(I%-1,9)=Y(I%-1,1):FOR J%=1 TO 400
  87.      IF Y(I%-1,J%)<=LIM(I%-1,8) THEN LIM(I%-1,8)=Y(I%-1,J%) ELSE IF Y(I%-1,J%)>=LIM(I%-1,9) THEN LIM(I%-1,9)=Y(I%-1,J%)
  88.      NEXT:NEXT:RETURN
  89.  
  90. '    Subroutine to calculate absolute units for screen plotting
  91. '    x%(0) is the x axis offset (in absolute units)        x%(2) is the y axis offset (in absolute units)
  92. '    xd is the x-value in user units                       yd is the y-value in user units
  93. '    lim(set,2) is the x(min) in user units                lim(set),4) is the y(min) in user units
  94. '    dx(set) = x(max)-x(min) in user units                 dy(set) = y(max-y(min) in user units
  95. '    xspan = (max no. of units on x-axis)-x%(0)            yspan = (max no. of units on y-axis)-x%(2)
  96. 1620 X=X%(0)+(XD-LIM(SET%-1,2))/DX(SET%-1)*XSPAN:Y=X%(2)+(YD-LIM(SET%-1,4))/DY(SET%-1)*YSPAN:RETURN:'XD,YD in user units
  97.  
  98. '    Subroutine to keep plotting within specified limits (window)
  99. 1630 IF LIM%=0 THEN RETURN:' axis, legends, title and notes are outside the limits
  100.      IF YD<LIM(SET%-1,4) THEN YD=LIM(SET%-1,4) ELSE IF YD>LIM(SET%-1,5) THEN YD=LIM(SET%-1,5)
  101.      RETURN:' just draw line on the limit (upper or lower one)
  102.  
  103. '    Subroutine to display the exit menu
  104. 1700 M%=22:N%=1:GOSUB 1110:INPUT"Type R to repeat the routine or type E to exit: ",A$
  105.      IF A$<>"R" THEN IF A$<>"E" THEN 1700:' only capital letters are accepted
  106.      IF A$="R" THEN GOSUB 5040:ON G%(1) GOSUB 6110,6210,6310,6410:' repeat routines (nested GOSUB no ret to here)
  107.      RETURN:' exiting and chaining
  108.  
  109. '                  Subroutines to setup the graphics screen
  110. '                  ----------------------------------------
  111.  
  112. '    Subroutine to display heading
  113. 3000 GOSUB 1100:M%=1:N%=1:GOSUB 1130:PRINT"<";F1$;">":M%=2:GOSUB 1130:print string$(76,61):M%=1
  114.      IF G%(1)=1 THEN A$="Plot of experimental points":N%=INT(40-(LEN(A$))/2):GOSUB 1130:PRINT A$
  115.      IF G%(1)=2 THEN A$="Plot spline functions":N%=INT(40-(LEN(A$))/2):GOSUB 1130:PRINT A$
  116.      IF G%(1)=3 THEN A$="Plot regression function":N%=INT(40-(LEN(A$))/2):GOSUB 1130:PRINT A$
  117.      IF G%(1)=4 THEN A$="Plot user defined function":N%=INT(40-(LEN(A$))/2):GOSUB 1130:PRINT A$
  118.      M%=1:N%=INT(76-LEN(F2$)):GOSUB 1130:PRINT"<";F2$;">":RETURN
  119.  
  120. '    Subroutine to display and change the graphics screen data (abs. plotting units)
  121. '    This one is for the GDC-512 which has 512x490 pixels. Change to suit.
  122. '    NOTE - the gdc512 has actually two screens 512x419 pixels each, but only one can be displayed at time.  For the
  123. '    compatibility reason only ONE page is used here.  See also note at label 6000.
  124. 3100 M%=4:N%=1:GOSUB 1130:PRINT"Total plotting area is 512 X 490 abs. units.":M%=5:GOSUB 1130
  125.      PRINT"The default plotting area (in abs. units):";:PRINT USING L$;X%(1)-X%(0);:PRINT" X";
  126.      PRINT USING L$;X%(3)-X%(2):M%=7:N%=5:GOSUB 1130:PRINT"X(start), abs. units: ";:PRINT USING L$;X%(0):M%=8
  127.      GOSUB 1120:PRINT"X(end), abs. units:   ";:PRINT USING L$;X%(1):M%=9:GOSUB 1120:PRINT"Y(start), abs. units: ";
  128.      PRINT USING L$;X%(3):M%=10:GOSUB 1120:PRINT"Y(end), abs. units:   ";:PRINT USING L$;X%(3):GOSUB 5070
  129.      M%=22:N%=1:GOSUB 1120:INPUT"OK (Y)? ",A$:IF A$<>"N" THEN RETURN ELSE 3110
  130. 3110 N%=35:FOR M%=7 TO 10:GOSUB 1130:INPUT"? ",A$:IF A$=""THEN 3120 ELSE X%(M%-6)=VAL(A$)
  131. 3120 NEXT:M%=4:N%=1:GOSUB 1110:GOSUB 5040:GOSUB 1000:GOSUB 4060:GOSUB 4070:GOTO 3100:' change data, show new frame
  132.  
  133. '    Subroutine to display and change limits for plots
  134. 3200 M%=2:N%=1:GOSUB 1110:' clear to the end of page
  135.      M%=5:N%=4:GOSUB 1110:PRINT"X(0), (user units):    ":M%=6:GOSUB 1120:PRINT"Y(0), (user units):    "
  136.      M%=8:N%=4:GOSUB 1120:PRINT"X(MIN), (user units):  ":M%=9:GOSUB 1120:PRINT"X(MAX), (user units):  "
  137.      M%=10:GOSUB 1120:PRINT"Y(MIN), (user units):  ":M%=11:GOSUB 1120:PRINT"Y(MAX), (user units):  "
  138.      M%=13:GOSUB 1120:PRINT"X-divisions:           ":M%=14:GOSUB 1120:PRINT"Y-divisions:           "
  139.      M%=16:GOSUB 1120:PRINT"min of F(x), (user units): ":M%=17:GOSUB 1120:PRINT"max of F(x), (user units): "
  140.      M%=4:N%=30:FOR I%=0 TO 9:M%=M%+1:GOSUB 1130:IF I%=1 OR I%=5 OR I%=7 THEN M%=M%+1
  141.      PRINT STR$(LIM(SET%-1,I%)):NEXT
  142. 3210 M%=22:N%=1:GOSUB 1110:INPUT"OK (Y/N)?",A$:IF A$<>"N" and A$<>"Y" THEN 3210
  143.      IF A$="Y" THEN 3220 ELSE 3230
  144. 3220 GOSUB 1110:INPUT"Save the data (N)?",A$:IF A$<>"Y" THEN return else GOSUB 1540:RETURN:' save data?
  145. 3230 GOSUB 1530:IF A$="K" THEN 3240 ELSE 3200:' fill-in the name of the file with limits/change lims from KB
  146. 3240 M%=4:FOR I%=0 TO 7:M%=M%+1:N%=32+LEN(STR$(LIM(SET%-1,I%))):GOSUB 1130
  147.      IF I%=1 OR I%=5 THEN M%=M%+1:' just for readable spacing between data
  148.      INPUT" ";A$:IF A$="" THEN 3250 ELSE LIM(SET%-1,I%)=VAL(A$):' RET means no change, else type the data
  149. 3250 NEXT:GOTO 3200:' when change finished, display again changed values (end of change lims. sub.!)
  150.  
  151.  
  152. '                    Subroutines to perform the graphics
  153. '                    -----------------------------------
  154.  
  155. '    Subroutine to plot experimental points on the graphics screen (as little crosses)
  156. 4000 F1$="plot dots":GOSUB 3000:M%=4:N%=1:GOSUB 1110:M%=22:GOSUB 1120:INPUT"Draw points (Y)? ",A$:IF A$="N" THEN RETURN
  157.      FOR I%=1 TO G%(3+SET%):XD=XD(SET%-1,I%)-.01*DX(SET%-1):YD=YD(SET%-1,I%):GOSUB 1620:GOSUB 5060
  158.      XD=XD(SET%-1,I%)+.01*DX(SET%-1):GOSUB 1620:GOSUB 5080:XD=XD(SET%-1,I%):YD=YD(SET%-1,I%)-.01*DY(SET%-1)
  159.      GOSUB 1620:GOSUB 5060:YD=YD(SET%-1,I%)+.01*DY(SET%-1):GOSUB 1620:GOSUB 5080:NEXT:RETURN
  160.  
  161. '    Subroutine to draw axis at XD(SET%,0),YD(SET%,0)
  162. 4010 f1$="draw axis":GOSUB 3000:M%=4:N%=1:GOSUB 1110:M%=22:GOSUB 1120:INPUT"Draw axis (Y)? ",A$:IF A$="N" THEN RETURN
  163.      LIM%=0:XD=LIM(SET%-1,2):YD=LIM(SET%-1,1):GOSUB 1620:GOSUB 5060:XD=LIM(SET%-1,3):GOSUB 1620:GOSUB 5080
  164.      XD=LIM(SET%-1,0):YD=LIM(SET%-1,4):GOSUB 1620:GOSUB 5060:YD=LIM(SET%-1,5):GOSUB 1620:GOSUB 5080:LIM%=1:RETURN
  165.  
  166. '    Subroutine to draw ticks and labels
  167. 4020 f1$="draw labels":GOSUB 3000:M%=4:N%=1:GOSUB 1110:M%=22:GOSUB 1120:INPUT"Draw ticks and labels (Y)? ",A$
  168.      IF A$="N" THEN RETURN else LIM%=0:FOR I%=0 TO LIM(SET%-1,6):XD=LIM(SET%-1,2)+I%*DX(SET%-1)/LIM(SET%-1,6)
  169.      YD=LIM(SET%-1,1)+.01*DY(SET%-1):GOSUB 1620:GOSUB 5060:YD=LIM(SET%-1,1)-.01*DY(SET%-1):GOSUB 1620:GOSUB 5080
  170.      YD=LIM(SET%-1,1)-.05*DY(SET%-1):GOSUB 1620:GOSUB 5060:MODE%=0:GOSUB 5100:FOR J%=2 TO LEN(STR$(XD))
  171.      BIT%=ASC(MID$(STR$(XD),J%,1)):GOSUB 5090:NEXT:NEXT:M%=39:N%=45-LEN(X$)/2:GOSUB 5050:FOR J%=1 TO LEN(X$)
  172.      BT%=ASC(MID$(X$,J%,1)):GOSUB 5010:NEXT:FOR I%=0 TO LIM(SET%-1,7):YD=LIM(SET%-1,4)+I%*DY(SET%-1)/LIM(SET%-1,7)
  173.      XD=LIM(SET%-1,0)-.01*DX(SET%-1):GOSUB 1620:GOSUB 5060:XD=LIM(SET%-1,0)+.01*DX(SET%-1):GOSUB 1620:GOSUB 5080
  174.      XD=LIM(SET%-1,0)-.1*DX(SET%-1):GOSUB 1620:GOSUB 5060:MODE%=0:GOSUB 5100:FOR J%=1 TO LEN(STR$(YD))
  175.      BIT%=ASC(MID$(STR$(YD),J%,1)):GOSUB 5090:NEXT:NEXT:LIM%=1:RETURN
  176.  
  177. '    Subroutine to draw a title of the plot; for the plot points and plot spline functions options the title can be
  178. '    entered from the keyboard, but for the regression function the title is stored in a sequential file PLOT03.DOC.
  179. '    There are 8 records of numerical values of the regression coefficients of the respective models.
  180. 4030 IF G%(1)=3 THEN 4050:' to a special routine for the regression functions
  181. 4040 M%=22:N%=1:GOSUB 1120:INPUT"Legend (Y/N)",A$:IF A$<>"Y" THEN IF A$<>"N" THEN IF A$<>"" THEN 4040:'ret=same legend
  182.      IF A$="N" THEN X$="" ELSE IF A$="Y" THEN LINE INPUT"(max. 80 chars.) ",X$:' type the new legend
  183.      GOSUB 1100:RETURN:' N cancells the previous legend
  184. 4050 OPEN"I",#1,"PLOT03.DOC":' open the file and read the appropriate record (model number is in the SET% variable)
  185.      FOR REC%=1 TO SET%:INPUT#1,A$:NEXT:CLOSE:X$=A$:RETURN:' then get the record, close file and return
  186.  
  187. '    Subroutine to draw a frame around the whole graphics screen (not really needed all the time)
  188. '    the dealy subroutine is called from here, if you are going not to use this routine the comment out the delay too
  189. 4060 X=0:Y=0:GOSUB 5060:X=511:GOSUB 5080:GOSUB 1000:Y=489:GOSUB 5080:GOSUB 1000:X=0:GOSUB 5080:GOSUB 1000
  190.      Y=0:GOSUB 5080:RETURN
  191.  
  192. '    Subroutine to draw a frame around the plotting area (not really needed all the time)
  193. '    the dealy subroutine is called from here, if you are going not to use this routine the comment out the delay too
  194. 4070 X=X%(0):Y=X%(2):GOSUB 5060:X=X%(1):GOSUB 5080:GOSUB 1000:Y=X%(3):GOSUB 5080:GOSUB 1000:X=X%(0):GOSUB 5080
  195.      Y=X%(2):GOSUB 5080:RETURN
  196.  
  197.  
  198. '              Subroutines to handle the GDC-512 Graphics board
  199. '              ------------------------------------------------
  200. '    bt% is a byte send to the board, wd% is a word send to the board
  201.  
  202. '    Subroutines to send data to the GDC-512 board
  203. '    (The Status port is 241 and the Data port is 240.  Change to suit.)
  204. 5000 BT%=INT(WD%/256):GOSUB 5010:BT%=(WD% AND 255):GOSUB 5010:RETURN:' Subroutine to output a 16-bit data
  205. 5010 IF (INP(STATP%) AND 1)>0 THEN 5010 ELSE OUT(DATP%),(BT% AND 255):RETURN:' Subroutine to output a 8-bit data
  206.  
  207. '    Subroutine to clear graphics and reset alpha cursor
  208. 5040 M%=22:N%=1:GOSUB 1110:INPUT"Clear graphics (N)? ",a$:if a$<>"Y" then return
  209.      OUT(STATP%),1:OUT(STATP%),0:BT%=136:GOSUB 5010:BT%=12:GOSUB 5010:RETURN
  210.  
  211. '    Subroutine to set position of the alpha cursor
  212. 5050 BT%=129:GOSUB 5010:BT%=M%:GOSUB 5010:BT%=N%:GOSUB 5010:RETURN
  213.  
  214. '    Subroutine to set graphics cursor to x,y coordinates
  215. 5060 BT%=132:GOSUB 5010:WD%=X:GOSUB 5000:WD%=Y:GOSUB 5000:RETURN
  216.  
  217. '    Subroutine to reset the GDC512 but not to clear the graphics
  218. 5070 OUT(STATP%),1:OUT(STATP%),0:GOSUB 1000:RETURN
  219.  
  220. '    Subroutine to draw a line from the current position to x,y
  221. 5080 BT%=145:GOSUB 5010:WD%=X:GOSUB 5000:WD%=Y:GOSUB 5000:RETURN
  222.  
  223. '    Subroutine to plot character at current location of graphics cursor
  224. 5090 BT%=152:GOSUB 5010:BT%=BIT%:GOSUB 5010:RETURN
  225.  
  226. '    Subroutine to set character mode; direction, size, normal/reverse video
  227. 5100 BT%=153:GOSUB 5010:BT%=MODE%:GOSUB 5010:RETURN
  228.  
  229.  
  230. '                      The MAIN section of the program
  231. '                      ===============================
  232.  
  233. 6000 GOSUB 1100:M%=22:N%=1:GOSUB 1120:F$="PLOT.FLG":FL%=2:GOSUB 1500:GET#1,1:G%(0)=CVI(R$):FOR I%=1 TO G%(0):GET#1,I%+1:' read flags
  234.      G%(I%)=CVI(R$):NEXT:CLOSE:IF G%(2)=1 THEN 6010:' choice of graphing on screen and plotter or on plotter only
  235.      INPUT"Plot on Graphics Screen too (N)";A$:IF A$<>"Y" THEN CHAIN"PLOT02.COM":' chain to plotter program
  236. 6010 GOSUB 1100:' the following line can be commented out if your system does not support pages
  237.      BT%=186:GOSUB 5010:BT%=3:GOSUB 5010:' select screen 0 for display and edit
  238.      F2$="Screen set-up":GOSUB 3000:GOSUB 3100:XSPAN=X%(1)-X%(0):YSPAN=X%(3)-X%(2):GOSUB 5040:' screen set-up
  239.      FOR I%=0 TO 7:LIM(I%,6)=10:LIM(I%,7)=10:NEXT:ON G%(1) GOTO 6100,6200,6300,6400:' set divs., then branch
  240.  
  241. '    The final branching point, all routines end here to chain complimentary programs
  242. 6050 IF G%(2)>1 THEN CHAIN"PLOT02.COM" ELSE KILL"PLOT.FLG":CHAIN"PLOT.COM"
  243.  
  244. '    routine to plot experimental points and connect these (if required) by a line
  245. 6100 F$="PLOT.$$$":FL%=4:GOSUB 1500:GOSUB 1510:GOSUB 1600:M%=2:N%=1:GOSUB 1110:' read data, get min/max, cls
  246. 6110 M%=22:N%=1:GOSUB 1120:PRINT"There are";G%(3);:INPUT" set(s) of data. Which set to plot";A$:SET%=VAL(A$)
  247.      IF SET%<1 OR SET%>G%(3) THEN 6110:' check for validity of the number of sets
  248.      F2$="set no.:"+STR$(SET%):GOSUB 1100:GOSUB 3000:GOSUB 3200:' display header, get the plotting limits
  249.      DX(SET%-1)=LIM(SET%-1,3)-LIM(SET%-1,2):DY(SET%-1)=LIM(SET%-1,5)-LIM(SET%-1,4)
  250.      GOSUB 4000:M%=22:N%=1:GOSUB 1110:INPUT"Connect these points by lines (Y)? ",A$:IF A$="N" THEN 6120
  251.      XD=XD(SET%-1,1):YD=YD(SET%-1,1):GOSUB 1620:GOSUB 5060:FOR I%=2 TO G%(3+SET%):XD=XD(SET%-1,I%):YD=YD(SET%-1,I%)
  252.      GOSUB 1620:GOSUB 5080:NEXT:' set graphics cursor to first point, then draw line from point to point
  253. 6120 GOSUB 4030:GOSUB 4010:GOSUB 4020:GOSUB 1700:GOTO 6050:' do axis and labels and (if required) legend, repeat?
  254.  
  255. '    plot spline function routine (one set of data for f(x), f'(x), f''(x); set no.=function to plot)
  256. 6200 G%(3)=1:F$="PLOT.$$$":FL%=4:GOSUB 1500:GOSUB 1510:GOSUB 1600:' read exptl points, calc min/max
  257.      G%(3)=3:F$="PLOT02.DAT":GOSUB 1500:GOSUB 1520:GOSUB 1610:' read all functions points, calc all min/max
  258.      SET%=1:FOR I%=0 TO 7:LIM(I%,6)=10:LIM(I%,7)=10:LIM(I%,2)=LIM(0,2):LIM(I%,3)=LIM(0,3):NEXT:' defaults xmin/xmax
  259. 6210 GOSUB 1100:GOSUB 3000:M%=22:N%=1:GOSUB 1120:INPUT"Type F to plot f(x), D1 to plot f'(x), D2 to plot f''(x) ",A$
  260.      IF A$<>"F" THEN IF A$<>"D1" THEN IF A$<>"D2" THEN 6210:' choose function to plot
  261.      IF A$="D1" THEN SET%=2:F2$="plot of f'(x)":GOSUB 3000:GOSUB 3200:' get limits
  262.      IF A$="D2" THEN SET%=3:F2$="plot of f''(x)":GOSUB 3000:GOSUB 3200:' get limits
  263.      IF A$="F" THEN SET%=1:F2$="plot of f(x)":GOSUB 3000:GOSUB 3200:' function plot
  264.      DX(SET%-1)=LIM(SET%-1,3)-LIM(SET%-1,2):DY(SET%-1)=LIM(SET%-1,5)-LIM(SET%-1,4):IF SET%=1 THEN GOSUB 4000:' dots?
  265.      XD=X(1):YD=Y(SET%-1,1):GOSUB 1620:GOSUB 5060:FOR I%=2 TO 400:XD=X(I%):YD=Y(SET%-1,I%):GOSUB 1620:GOSUB 5080:NEXT
  266.      GOSUB 4030:GOSUB 4010:GOSUB 4020:GOSUB 1700:GOTO 6050:' ask for legend, draw axis with labels and ticks, repeat?
  267.  
  268. '    family regression analysis routine (one data set for all 8 models; set no. is model no.)
  269. 6300 G%(3)=1:F$="PLOT.$$$":FL%=4:GOSUB 1500:GOSUB 1510:GOSUB 1600:' read all the data, calc min/max
  270.      FOR I%=1 TO 7:G%(I%+4)=G%(4):FOR J%=1 TO G%(4):XD(I%,J%)=XD(0,J%):YD(I%,J%)=YD(0,J%):NEXT:NEXT
  271.      FOR I%=1 TO 7:FOR J%=0 TO 9:LIM(I%,J%)=LIM(0,J%):NEXT:NEXT:' exptl data the same for all 8 models
  272.      G%(3)=8:F$="PLOT03.DAT":GOSUB 1500:GOSUB 1520:GOSUB 1610:' get points and limits for all models, calc min/max
  273. 6310 GOSUB 1100:F1$="":F2$="regression models":GOSUB 3000:M%=3:N%=8:GOSUB 1120:PRINT"1.  Y = A + B * X":M%=5:GOSUB 1120
  274.      PRINT"2.  Y = A + B / X":M%=7:GOSUB 1120:PRINT"3.  (1/Y) = A + B * (1/X)":M%=9:GOSUB 1120
  275.      PRINT"4.  Y = B * X^(1/2)":M%=11:GOSUB 1120:PRINT"5.  Y = A * exp(B * X)":M%=13:GOSUB 1120:PRINT"6.  Y = A * X^B"
  276.      M%=15:GOSUB 1120:PRINT"7.  Y = A + B * ln(X)":M%=17:GOSUB 1120:PRINT"8.  Y = A + B * X + C * X^2"
  277. 6320 M%=22:N%=1:GOSUB 1110:INPUT"Type the number of your selected regression model: ",A$:SET%=VAL(A$)
  278.      F2$="model no."+STR$(SET%):IF SET%<1 OR SET%>8 THEN 6320:' get legal limits else loop
  279.      GOSUB 3200:FOR L%=0 TO 7:DX(L%)=LIM(L%,3)-LIM(L%,2):DY(L%)=LIM(L%,5)-LIM(L%,4):NEXT:GOSUB 4000:' lims, plot points
  280.      XD=X(1):YD=Y(SET%-1,1):GOSUB 1630:GOSUB 1620:GOSUB 5060:FOR I%=2 TO 400:XD=X(I%):YD=Y(SET%-1,I%):GOSUB 1630
  281.      GOSUB 1620:GOSUB 5080:NEXT:GOSUB 4030:GOSUB 4010:GOSUB 4020:GOSUB 1100:GOSUB 3000::' draw plot, cls, header
  282.      GOSUB 1700:GOTO 6050:' repeat or end this routine?
  283.  
  284. '    plot user's function routine
  285. '    Here we can have up to 8 sets of experimental data for 8 sets of functions.  We read only those experimental data
  286. '    that were entered BUT we read ALL 8 sets of function points regardless
  287. 6400 GOSUB 1100:' cls, display header, if any experimantal data then read them
  288.      IF G%(2)<3 THEN F$="PLOT.$$$":FL%=4:F1$=F$:GOSUB 3000:GOSUB 1500:GOSUB 1510:GOSUB 1600:' read data, min/max
  289.      G%=8:SWAP G%,G%(3):F$="PLOT04.DAT":FL%=4:F1$=F$:GOSUB 3000:GOSUB 1500:GOSUB 1520:GOSUB 1610:swap g%,g%(3)
  290.      FOR L%=0 TO 7:DX(L%)=LIM(L%,3)-LIM(L%,2):DY(L%)=LIM(L%,5)-LIM(L%,4):NEXT:' get proper x nad y ranges
  291. 6410 GOSUB 3000:M%=3:N%=1:GOSUB 1110:IF G%(2)<3 THEN 6420 ELSE 6430:' if no data then function perhaps
  292. 6420 M%=22:N%=1:GOSUB 1120:PRINT"There are";G%(3);:INPUT" set(s) of data. Which set to plot";A$
  293.      SET%=VAL(A$):F2$="Set no."+STR$(SET%):IF SET%<1 OR SET%>8 THEN 6410:' set proper plotting limits and plot points
  294.      GOSUB 3000:GOSUB 3200:DX(SET%-1)=LIM(SET%-1,3)-LIM(SET%-1,2):DY(SET%-1)=LIM(SET%-1,5)-LIM(SET%-1,4):GOSUB 4000
  295. '    Here we draw a function curve.  It is assumed here that the user knows how many curves to plot.  There is NO
  296. '    checking on validity of the data - unwritten data will be read and plotted
  297. 6430 M%=22:N%=1:GOSUB 1120:INPUT"Plot function for set number: ",A$:A=VAL(A$):IF A=0 THEN GOSUB 1700:' exit perhaps?
  298.      IF A<1 OR A>8 THEN 6430 ELSE SET%=A:' we have an existing function number
  299.      F2$="Set no."+STR$(SET%):GOSUB 3000:GOSUB 3200:DX(SET%-1)=LIM(SET%-1,3)-LIM(SET%-1,2):' get new ranges
  300.      DY(SET%-1)=LIM(SET%-1,5)-LIM(SET%-1,4):XD=X(1):YD=Y(SET%-1,1):GOSUB 1630:GOSUB 1620:GOSUB 5060:'set graphics cursor
  301.      FOR I%=2 TO 400:XD=X(I%):YD=Y(SET%-1,I%):GOSUB 1630:GOSUB 1620:GOSUB 5080:NEXT:' draw the function
  302.      GOSUB 4030:GOSUB 4010:GOSUB 4020:GOSUB 1100:GOSUB 3000:' title?, axis?, ticks and labels?, cls, display header
  303.      GOSUB 1700:GOTO 6050:' repeat or end this routine?
  304. END
  305.