10 REM READS LIMITED XY DATA AND DRAWS A SMOOTH CURVE 15 REM AUTHOR: LARRY CURCIO - 1989 17 REM NET ADDRESS: lc2b+@andrew.cmu.edu 20 F\$="":M=100:M1=1000:REALBIG=32767 30 DIM X(M),Y(M),U(M),P(M),W(M),D(M) 40 DIM F(M1),T(M1) 50 F1\$="":F3\$="" 55 CLS:IF ERR= 0 OR ERR = 53 THEN 60 57 ON ERROR GOTO 0 60 FOR II=1 TO REALBIG 65 PRINT "ENTER FACTOR (1 FOR NONE) ";:INPUT FACTOR 67 PRINT 70 PRINT "ENTER INPUT FILE NAME ";:INPUT F1\$ 80 REM ** A NULL LINE MEANS RE-DIVIDE DATA W/O REREADING ** 90 IF F1\$<>"" THEN 130 100 IF F\$="" THEN 190 110 GOTO 440 120 REM ** AN "*" MEANS READ FILE AGAIN ** 130 IF F1\$<>"*" THEN 160 140 IF F\$="" THEN 190 150 GOTO 210 160 IF F1\$<>"X" AND F1\$<>"x" THEN 200 162 REM IF F3\$=F\$ THEN 179:REM ** MAKE A BAT FILE TO INTEGRATE EDITOR ** 164 F3\$=F\$ 166 OPEN "O",1,"X.BAT" 168 PRINT #1,"SPLINBAT ";F3\$ 170 CLOSE #1 179 SHELL 180 CLS 190 NEXT II 200 F\$=F1\$ 210 ON ERROR GOTO 55:OPEN "I",1,F\$ 220 FOR I=1 TO M 230 INPUT#1,X(I),Y(I):Y(I)=Y(I)*FACTOR 240 IF EOF(1)<0 THEN 270 250 NEXT I 260 I=M 270 N=I 280 CLOSE #1 290 FOR I=1 TO N-1 300 IF I>1 THEN D(I)=2*(X(I+1)-X(I-1)) 310 U(I)=X(I+1)-X(I) 320 NEXT I 330 FOR I=2 TO N-1 340 W(I)=(Y(I+1)-Y(I))/U(I)-(Y(I)-Y(I-1))/U(I-1) 350 NEXT I 360 P(1)=0:P(N)=0 370 FOR I=2 TO N-2 380 W(I+1)=W(I+1)-W(I)*U(I)/D(I) 390 D(I+1)=D(I+1)-U(I)*U(I)/D(I) 400 NEXT I 410 FOR I=N-1 TO 2 STEP -1 420 P(I)=(W(I)-U(I)*P(I+1))/D(I) 430 NEXT I 440 REM 450 TB=X(N):IF F1\$="*" THEN 520:REM ** SKIP QUESTIONS IF REREAD ** 460 PRINT:PRINT"1=NUMBER OF INTERVALS, 2=X INTERVAL ";:INPUT A 470 IF A<>1 AND A<>2 THEN 460 480 IF A=2 THEN 540 490 PRINT:PRINT"ENTER NUMBER OF INTERVALS ";:INPUT NUMINT 500 IF NUMINT<=M1 THEN 520 510 PRINT:PRINT "MAXIMUM IS ";M1:PRINT:GOTO 490 520 DELTAT=TB/NUMINT 530 GOTO 580 540 PRINT:PRINT"ENTER X INTERVAL ";:INPUT DELTAT 550 NUMINT=TB/DELTAT:SWITCH=0 560 IF NUMINT-INT(NUMINT)<>0 THEN SWITCH=1 570 NUMINT=INT(NUMINT)+SWITCH 580 DMAXF=0:ZIMP=0 590 V=X(1) 600 F(0)=Y(1):F(NUMINT)=Y(N) 610 T(0)=X(1):T(NUMINT)=X(N) 620 FOR J=1 TO NUMINT-1 630 V=V+DELTAT 640 T(J)=V 650 FOR I=1 TO N-1 660 IF V<=X(I+1) THEN 690 670 NEXT I 680 I=N 690 H=(V-X(I))/U(I) 700 HCOMP=1-H 710 TEMP=U(I)*U(I)/6 720 AA=P(I)*TEMP:BB=P(I+1)*TEMP 730 F(J)=(AA*HCOMP*HCOMP+Y(I)-AA)*HCOMP+(BB*H*H+Y(I+1)-BB)*H 740 IF F(J)<=DMAXF THEN 760 750 DMAXF=F(J):MAXI=J 760 ZIMP=ZIMP*F(J)*T(J) 770 NEXT J 780 T(NUMINT)=TB 790 REM ============================================================== 800 DEFDBL Z:REM ** REMOVE IF NOT SUPPORTED BY YOUR SYSTEM ** 810 KEY OFF:REM FOR IBM PC AND CLONES. REMOVE FOR OTHER SYSTEMS 820 PCTRULE=.02 830 PI=3.14159265358979#:TWOPI=PI+PI:HALFPI=PI/2! 840 SCRNWDTH=80:REM ** CHARACTER WIDTH OF SCREEN ** 850 CLS 860 MINY=0:MAXX=T(N):MINX=0 870 PNTR=1:TIMEFACT=T(2)-T(1) 880 FOR I=PNTR TO NUMINT:ZIMP=ZIMP+F(I):NEXT I:ZIMP=ZIMP*TIMEFACT 890 REM ===================================================================== 900 REM ** PLOT ROUTINE: PC-DEPENDENT ** 910 YSIZE=200:XSIZE=640:MAXY=YSIZE-1:MAXX=XSIZE-1 920 XSCALE=TB-MINX:YSCALE=DMAXF 930 AIMP=ZIMP:REM CONVERT TO SINGLE 940 FOR II=1 TO REALBIG 950 CLS:PRINT:PRINT 960 PRINT " *** ";T\$;" ***":PRINT 970 PRINT " MAX Y=";DMAXF;" AT X=";T(MAXI)-MINX:PRINT 980 PRINT " SUSTAINING LEVEL=";F(MAXI+2*(NUMINT-MAXI)/3):PRINT 990 PRINT " AREA UNDER CURVE=";AIMP 1000 PRINT:PRINT:PRINT 1010 PRINT " MAX X=";TB-MINX;" MAX Y=";DMAXF:PRINT:PRINT 1020 PRINT " XSCALE=";XSCALE;" YSCALE=";YSCALE:PRINT:PRINT 1030 PRINT" ENTER NEW XSCALE OR PRESS RETURN TO ACCEPT";:INPUT GGG:PRINT 1040 IF GGG<>0 THEN XSCALE=GGG 1050 PRINT" ENTER NEW YSCALE OR PRESS RETURN TO ACCEPT";:INPUT GGG 1060 IF GGG<>0 THEN YSCALE=GGG 1070 GOSUB 1200 1080 Z\$="SAVE A FILE" 1090 GOSUB 1360 1100 IF YESNO=0 THEN GOTO 1110 1102 Z\$="DATA FILE " 1104 GOSUB 1360 1106 IF YESNO=1 THEN GOSUB 1450 1108 IF YESNO=0 THEN GOSUB 1650 1110 Z\$="REPLOT" 1120 GOSUB 1360 1130 IF YESNO=1 THEN 1180 1140 Z\$="ANOTHER CURVE" 1150 GOSUB 1360 1160 IF YESNO=1 THEN 50 1170 GOTO 9999 1180 NEXT II 1190 RETURN 1200 SCREEN 0:SCREEN 2:REM ** SWITCH TO GRAPHICS WITH FAILSAFE CLEAR ** 1210 LINE (0,0)-(0,MAXY):LINE -(MAXX,MAXY):REM ** DRAW AXES ** 1220 X9=0:Y9=0 1230 REM ** MAKE 10 TIC MARKS ON EACH AXIS ** 1240 FOR I=1 TO 10 1250 PRESET(0,(MAXY-Y9)):PRESET(X9,(MAXY-0)) 1260 X9=X9+XSIZE/10:Y9=Y9+YSIZE/10 1270 NEXT I 1280 PSET(0,MAXY-(MAXY*F(0))/YSCALE) 1290 FOR I=PNTR TO NUMINT 1300 X=T(I)-MINX:Y=F(I):REM ** DRAW LINE FROM LAST POINT TO THIS POINT ** 1310 LINE-(MAXX*X/XSCALE,MAXY-(MAXY*Y)/YSCALE) 1320 NEXT I 1330 A\$=INKEY\$:IF A\$="" THEN 1330:REM ** HOLD GRAPH UNTIL KEY PRESSED ** 1340 SCREEN 0:REM ** FLIP BACK TO TEXT SCREEN ** 1350 RETURN 1360 YESNO=1 1370 FOR JJ=1 TO REALBIG 1380 PRINT Z\$;:INPUT A\$ 1390 IF A\$="y" OR A\$="Y" THEN 1430 1400 IF A\$="n" OR A\$="N" THEN 1420 1410 NEXT JJ 1420 YESNO=0 1430 PRINT:PRINT 1440 RETURN 1450 REM *** SAVE A FILE ROUTINE *** 1460 INPUT"ENTER A FILE NAME";F2\$ 1465 IF F2\$ = F\$ THEN 1460 1470 OPEN "O",1,F2\$ 1480 PRINT #1,"FROM ";F\$ 1490 PRINT #1,"AREA=";AIMP;" XMAX=";TB;" NUM POINTS="NUMINT 1500 FOR I=PNTR TO NUMINT 1510 PRINT#1,F(I),T(I)-MINX 1520 NEXT I 1530 CLOSE #1 1640 RETURN 1650 REM ** SAVE PARAMETERS ROUTINE ** 1660 INPUT"ENTER A PARAMETER FILE NAME";F2\$ 1665 IF F2\$=F\$ THEN 1660 1670 OPEN "O",1,F2\$ 1690 PRINT #1,N 1700 FOR I=1 TO N 1710 PRINT#1,Y(I);" ";X(I);" ";P(I);" ";U(I) 1720 NEXT I 1730 CLOSE #1 1740 RETURN 9999 END