|
25 Years of Programming
An open source source for C, C++, OWL, BASIC, MDB, XLS, DOT, and more... |
Home Projects Up Sitemap Search Blog Forum+Chat About Us Privacy Terms of Use Feedback FAQ Images Services Ads Donate Humor |
GRAPH This program will allow you to graph the data in a previously-created data file against the data in any other previously-created data file. Either file can be graphed along either the x (horizontal) or y (vertical) axis. You will be asked for the name of the file to use for each axis. Manual or automatic scaling can be chosen for either or both axes. If automatic scaling is chosen, then the data will be graphed using the entire CRT screen, for the maximum possible resolution. If manual scaling is chosen, you will be asked for both the high and low values to use. For proper program operation, it is mandatory that the high value given be higher than the highest value contained in the file. Likewise, it is necessary that the low value given be lower than the lowest value contained in the file. It is suggested that a test run using automatic scaling be made prior to attempting manual scaling. Since the program uses screen character positions to plot the data, the resolution is necessarily somewhat crude, but is usually sufficient for most purposes. For the Y axis, each line is headed by the high interval value for that line. Numbers up to 99999.99 can be accommodated as the program is currently formatted. If a different format is needed, the variable N$ in line 140 can be changed. Each '#' sign before the decimal point stands for one digit of the printed number before the decimal point. Each '#' sign after the decimal point allows printing of one digit after the decimal point. However, the total number of digits should not exceed 7. For the X axis, the high interval values are plotted every 5 character positions. The entries are staggered high/low to allow for printing of very large or small numbers. Occasionally there will be no interval value printed. This is caused by the representation of the value being too large to center around the 5 character positions. Usually this means that the number is very close to zero (as 9.01527E-11) or is unusually large. The actual character that is plotted for each point can be changed in line 1240. The program automatically operates in the H89 graphics mode, so graphics characters can be used. An interesting, almost 3-dimensional effect can be created in (only) some cases by removing the character to be plotted and inserting instead (after removing also the quotation marks) the variable I+1. If this is done, the program will use as the plot character the number representing the position of that point in the array. That is, the first position plotted will bear the number 1, the second, 2, and so on. A use for this might be in a graph of a stock's price against the associated volume for consecutive days. The points plotted will show the relationship between price and volume, but not show the passage of time. Using this option, the passage of time can be shown by having the plotted points numbered. Before running the program, you should depress the 'CAPS LOCK' key on your keyboard, so that all of your responses are made in upper case.
The H89 program FILEMAKE.BAS helps create and manage the data files this program uses.
There is also a
graph program for GWBASIC / BASICA, which uses graphics mode for
higher resolution.
10 REM PROGRAM NAME GRAPH 20 REM COPYRIGHT (C)1982 STEVEN WHITNEY. 21 'Published under GNU GPL (General Public License) Version 2, with ABSOLUTELY NO WARRANTY. 30 PRINT CHR$(27)"F" : REM H89 (H19) GRAPHICS MODE (ALSO H100) 40 ON ERROR GOTO 1280 50 Q$=STRING$(75,"=") 60 DIM X(1000),Y(1000) 70 PRINT CHR$(27)"E":PRINT Q$:PRINT"THIS PROGRAM WILL PLOT IN GRAPH FORM A SERIES OF POINTS.":PRINT "THE POINTS ARE REFERRED TO IN THE FORM (X,Y), WHERE X IS THE ":PRINT"HORIZONTAL VALUE, AND Y IS THE VERTICAL." 80 PRINT:PRINT "THE VALUES FOR X MUST ALREADY BE STORED IN A DISK FILE." 90 PRINT "THE CORRESPONDING VALUES FOR Y MUST ALSO BE STORED IN A DISK FILE,":PRINT "IN THE SAME ORDER AS THE X VALUES.":PRINT 100 PRINT "THAT IS, THE PROGRAM WILL READ THE FIRST VALUE STORED IN THE X FILE,":PRINT "AND MATCH IT UP WITH THE FIRST VALUE STORED IN THE Y FILE TO MAKE" 110 PRINT "THE FIRST ORDERED PAIR (X1,Y1). THE SECOND NUMBERS FROM EACH FILE WILL BE":PRINT "PAIRED TO MAKE THE SECOND ORDERED PAIR (X2,Y2), AND SO ON." 120 PRINT Q$:PRINT 130 PRINT"IF NOT ALREADY DONE, PLEASE PRESS THE 'CAPS LOCK' KEY SO THAT ALL YOUR ":PRINT "RESPONSES ARE UPPER CASE.":PRINT STRING$(75,"="):PRINT 140 N$="#####.##" 150 INPUT "WHAT FILE HOLDS THE X AXIS VALUES";F$ 160 INPUT " WHAT WILL ITS TITLE BE";X$ 170 PRINT 180 PRINT "DO YOU WANT TO SCALE THE X AXIS MANUALLY? (Y/N)";:S1$=INPUT$(1):PRINT S1$:IF S1$<>"Y" AND S1$<>"N" THEN 180 190 IF S1$<>"Y" THEN 230 200 PRINT 210 INPUT "WHAT WILL THE LOW VALUE BE";LX 220 INPUT "WHAT WILL THE HIGH VALUE BE";HX 230 PRINT Q$:PRINT 240 INPUT "WHAT FILE HOLDS THE Y AXIS VALUES";G$ 250 INPUT " WHAT WILL ITS TITLE BE";Y$ 260 IF LEN(Y$)>20 THEN PRINT:PRINT,"==> PLEASE LIMIT TITLE TO 20 CHARACTERS":GOTO 250 270 PRINT 280 PRINT "SCALE Y AXIS MANUALLY? (Y/N)";:S2$=INPUT$(1):PRINT S2$:IF S2$<>"Y" AND S2$<>"N" THEN 280 290 IF S2$<>"Y" THEN 350 300 PRINT 310 INPUT "WHAT WILL THE LOW VALUE BE";LY 320 INPUT "WHAT WILL THE HIGH VALUE BE";HY 330 SWAP LY,HY : REM Y AXIS INVERTED 340 LY=-LY : HY=-HY : REM Y AXIS & VALUES INVERTED 350 OPEN "I",1,F$ 360 XN=-1 370 WHILE NOT EOF(1) 380 XN=XN+1 390 INPUT #1, X(XN) 400 WEND 410 CLOSE 420 OPEN "I",1,G$ 430 YN=-1 440 WHILE NOT EOF(1) 450 YN=YN+1 460 INPUT #1,Y(YN) 470 Y(YN)=-Y(YN) : REM INVERT FOR LATER PLOTTING HIGH MUST BE LOWEST! 480 WEND 490 CLOSE 500 IF XN<>YN THEN PRINT CHR$(27)"E";CHR$(7):PRINT Q$:PRINT"==> WARNING: THE TWO DATA FILES DO NOT CONTAIN THE SAME # OF POINTS.":PRINT "I WILL TRY TO PLOT POINTS FOR WHICH THERE ARE X VALUES, BUT THE GRAPHING":PRINT"MAY BE ERRATIC OR ERRONEOUS.":PRINT Q$ 510 IF XN<>YN THEN PRINT"PRESS ANY KEY TO ACKNOWLEDGE AND CONTINUE":Z$=INPUT$(1):PRINT " CALCULATING..." 520 REM ----------------------------------- 530 IF S1$="Y" THEN 660 540 REM FIND HIGH X VALUE 550 HX=-1.70141E+38 560 FOR I=0 TO XN 570 IF X(I)>=HX THEN HX=X(I) 580 NEXT I 590 REM --------------------------------- 600 REM FIND LOW X VALUE 610 LX=1.70141E+38 620 FOR I=0 TO XN 630 IF X(I)<=LX THEN LX=X(I) 640 NEXT I 650 REM FIND HIGH Y VALUE ------------------ 660 IF S2$="Y" THEN 770 670 HY=-1.70141E+38 680 FOR I=0 TO YN 690 IF Y(I)>=HY THEN HY=Y(I) 700 NEXT I 710 REM FIND LOW Y VALUE -------------------- 720 LY=1.70141E+38 730 FOR I=0 TO YN 740 IF Y(I)<=LY THEN LY=Y(I) 750 NEXT I 760 REM ------------------------------ 770 REM SCALE X VALUES TO THE EXACT VALUES TO BE PLOTTED (41 TO 111 GOING UP) 780 FOR I=0 TO XN 790 X(I)=INT((X(I)-LX)*(70/(HX-LX)))+41 800 NEXT I 810 REM SCALE Y VALUES TO THE EXACT VALUES TO BE PLOTTED (56 TO 31 GOING UP) 820 FOR I=0 TO YN 830 Y(I)=INT((Y(I)-LY)*(21/(HY-LY)))+32 840 NEXT I 850 REM PRINT GRAPH SKELETON--------------------- 860 PRINT CHR$(27)"E" : REM CLEAR SCREEN 870 PRINT CHR$(27)"x1" : REM ENABLE 25TH LINE 880 PRINT CHR$(27)"Y"CHR$(56)CHR$(32)CHR$(27)"E"TAB(10+((80-LEN(X$))/2));X$ : REM PRINT X LABEL 890 PRINT 900 FOR I=1 TO 22: PRINT CHR$(27)"Y"CHR$(I+31)CHR$(41)"-";: NEXT I : REM PRINT Y AXIS 910 PRINT 920 REM PRINT X AXIS 930 PRINT CHR$(27)"Y"CHR$(53)CHR$(41); 940 FOR I=10 TO 80 950 IF I/5=INT(I/5) THEN PRINT "I"; ELSE PRINT "-"; 960 NEXT I 970 REM PRINT Y LABEL 980 PRINT CHR$(27)"H" : REM HOME 990 FOR I=1 TO ((21-LEN(Y$))/2) : PRINT CHR$(27)"B"; : NEXT I : REM MOVE DOWN 1000 FOR I=1 TO LEN(Y$) 1010 PRINT MID$(Y$,I,1);CHR$(27)"B";CHR$(27)"D"; 1020 NEXT I 1030 REM PRINT Y AXIS NUMBERS---------------------------- 1040 FOR I=1 TO 22 1050 PRINT CHR$(27)"Y"CHR$(I+31)CHR$(33);USING N$;-(LY+(I-1)*(HY-LY)/21) 1060 NEXT I 1070 REM PRINT X AXIS NUMBERS ---------------------------------- 1080 PRINT CHR$(27)"Y"CHR$(53)CHR$(32); 1090 PRINT 1100 FOR I=1 TO 7 1110 TB=LX+(I-1)*10*(HX-LX)/70 1120 IF LEN(STR$(TB))/2>=5 THEN 1140 1130 PRINT TAB(I*10-LEN(STR$(TB))/2);TB; 1140 NEXT I 1150 PRINT 1160 FOR I=1.5 TO 7.5 1170 TB=LX+(I-1)*10*(HX-LX)/70 1180 IF LEN(STR$(TB))/2>=5 THEN 1200 1190 PRINT TAB(I*10-LEN(STR$(TB))/2);TB; 1200 NEXT I 1210 PRINT CHR$(27)"H" 1220 REM PLOT POINTS ------------------------------------------ 1230 FOR I=0 TO XN 1240 PRINT CHR$(27)"Y"CHR$(Y(I))CHR$(X(I));"^";CHR$(27)"H" 1250 NEXT I 1260 PRINT CHR$(27)"G" : REM EXIT GRAPHICS 1270 END 1280 IF ERR=53 AND (ERL=350 OR ERL=420) THEN PRINT CHR$(7):PRINT STRING$(75,"="):PRINT "ONLY THESE FILES ARE AVAILABLE: ":PRINT:FILES : PRINT STRING$(75,"="):PRINT ELSE GOTO 1310 1290 IF ERL=350 THEN RESUME 150 1300 IF ERL=420 THEN RESUME 240 1310 ON ERROR GOTO 0 1320 REM COPYRIGHT (C)1982 STEVEN WHITNEY.
|
|
|
|
|
|