home *** CD-ROM | disk | FTP | other *** search
- ~~QBASIC~~
- '--------------------------------------------------------------
- ' TableCurve QuickBASIC Library Module
- '--------------------------------------------------------------
- ' This code is specific to Microsoft QuickBASIC, and possibly
- ' version 4.0, which was used to construct this code. This
- ' version of QuickBASIC required separate libraries for the DOS
- ' Interrupt routines. It is therefore necessary to load QB with
- ' this quick library (qb.qlb) as follows: qb progname /L qb
- ' If using the command line, the qb.lib library must be linked
- ' in as with the following batch file commands:
- ' bc %1.bas /e/x/o;
- ' link /ex /noe %1,%1.exe,nul,qb.lib;
- ' ( The /e option is required because of error trapping. )
- ' The interrupt routines are used to set the screen attributes
- ' back to where they were before the program began and to
- ' determine whether color or monochrome attributes should be
- ' used. The code using these interrupts can be safely removed
- ' if these features are not wanted. QuickBASIC will also
- ' compile successfully without modification the code generated
- ' for BASICA/GWBASIC.
- '--------------------------------------------------------------
- ' The polynomial and rational equations use a polynomial
- ' calculation function rather than coding the equation on a
- ' single line. Such single line expressions are too complex for
- ' QuickBASIC to evaluate.
- '--------------------------------------------------------------
-
- DEFDBL x,y
- DEFINT i,j
- DIM x(17),y(17)
-
- '---- The following definitions are also in QB.BI -------------
- TYPE RegType
- ax AS INTEGER
- bx AS INTEGER
- cx AS INTEGER
- dx AS INTEGER
- bp AS INTEGER
- si AS INTEGER
- di AS INTEGER
- flags AS INTEGER
- END TYPE
- DECLARE SUB INTERRUPT (intnum AS INTEGER, inreg AS RegType, outreg AS RegType)
- DIM inreg AS RegType
- DIM outreg AS RegType
- '--------------------------------------------------------------
- DIM COEF#(11)`FPNRT`
- DECLARE FUNCTION `FNAME`# (X#)
- DECLARE FUNCTION numfld# (rowfld%, colfld%, maxlen%, istatus%)
- DECLARE FUNCTION evalpn# (order%, X#, cf#())
- DECLARE FUNCTION rtbis# (y#, dir%)
-
- ' Get screen attribute for reset at end of program
- inreg.ax = 8 * 256
- inreg.bx = 0
- CALL INTERRUPT(&H10, inreg, outreg)
- attr0% = outreg.ax \ 256
- fore0% = attr0% MOD 16
- back0% = attr0% \ 16
-
- ' Get present video mode for determining attributes
- inreg.ax = 15 * 256
- CALL INTERRUPT(&H10, inreg, outreg)
- ral% = outreg.ax MOD 256
- iscolor% = 1
- IF ((ral% = 0) OR (ral% = 2) OR (ral% = 7)) THEN iscolor% = 0
- IF iscolor% THEN
- fore1%=1 : back1%=7 : fore2%=15 : back2%=1
- ELSE
- fore1%=15 : back1%=0 : fore2%=0 : back2%=7
- END IF
-
- ' Main Window is Full Screen, Key Display is Off
- COLOR fore1%, back1%, back1%: CLS
- KEY OFF
- LOCATE 1,2 : PRINT CHR$(201);
- LOCATE 25,2 : PRINT CHR$(200);
- LOCATE 1,79 : PRINT CHR$(187);
- LOCATE 25,79 : PRINT CHR$(188);
- FOR I=3 TO 78 : LOCATE 1,I : PRINT CHR$(205); : NEXT I
- FOR I=3 TO 78 : LOCATE 25,I : PRINT CHR$(205); : NEXT I
- FOR I=2 TO 24 : LOCATE I,2 : PRINT CHR$(186); : NEXT I
- FOR I=2 TO 24 : LOCATE I,79 : PRINT CHR$(186); : NEXT I
- LOCATE 1,`POSN1`
- PRINT " TableCode `LANG` Function:`FILE` `DATE` `TIME` ";
-
- ' X-Y Data Window
- COLOR fore2%, back2%, back2%
- FOR I=5 TO 23 : LOCATE I,33 : PRINT SPACE$(45); : NEXT I
- LOCATE 5,33 : PRINT CHR$(218);
- LOCATE 24,33 : PRINT CHR$(192);
- LOCATE 5,77 : PRINT CHR$(191);
- LOCATE 24,77 : PRINT CHR$(217);
- FOR I=34 TO 76 : LOCATE 5,I : PRINT CHR$(196); : NEXT I
- FOR I=34 TO 76 : LOCATE 24,I : PRINT CHR$(196); : NEXT I
- FOR I=6 TO 23 : LOCATE I,33 : PRINT CHR$(179); : NEXT I
- FOR I=6 TO 23 : LOCATE I,77 : PRINT CHR$(179); : NEXT I
- LOCATE 5,`POSN2` : PRINT " `TITLE` ";
- LOCATE 6,35 : PRINT "`XTITLE`";
- LOCATE 6,57 : PRINT "`YTITLE`";
-
- ' Equation Data and Input Setup
- COLOR fore1%, back1%, back1%
- LOCATE 3,4 : PRINT "`EQSTR`";
- LOCATE 4,6 : PRINT "Eqn# `EQNO`";
- LOCATE 5,6 : PRINT "r2=`R2VAL`";
- LOCATE 6,6 : PRINT "a= `ASTR`";
- LOCATE 7,6 : PRINT "b= `BSTR`";
- LOCATE 8,6 : PRINT "c= `CSTR`";
- LOCATE 9,6 : PRINT "d= `DSTR`";
- LOCATE 10,6 : PRINT "e= `ESTR`";
- LOCATE 11,6 : PRINT "f= `FSTR`";
- LOCATE 12,6 : PRINT "g= `GSTR`";
- LOCATE 13,6 : PRINT "h= `HSTR`";
- LOCATE 14,6 : PRINT "i= `ISTR`";
- LOCATE 15,6 : PRINT "j= `JSTR`";
- LOCATE 16,6 : PRINT "k= `KSTR`";
- LOCATE 18,4 : PRINT "X= `XTITLE`";
- LOCATE 19,4 : PRINT "Y= `YTITLE`";
- LOCATE 21,4 : PRINT "Enter Value [x=,y=]";
- LOCATE 24,4 : PRINT "Press ESC to End Program";
-
- ' Data Input Loop, Exits only by ESCAPE
- irow=7
- iflag=1
- idir=0
- iatend=0
- ON ERROR GOTO MathError
- WHILE iflag
- LoopStart:
- j=irow-6
- COLOR fore2%,back2%,back2%
- IF idir=1 THEN idir=0 ELSE idir=1
- istatus=0
- xold=x(j)
- x(j)=numfld#(22,4,25,istatus)
- IF istatus = 0 THEN
- COLOR fore0%, back0%, back0%
- CLS
- SYSTEM
- ELSEIF istatus>0 THEN
- y(j)=`FNAME`#((x(j)))
- ELSE
- y(j)=x(j)
- x(j)=rtbis#(y(j),idir)
- END IF
- IF irow=23 THEN LOCATE 23,34 : PRINT SPACE$(42);
- LOCATE irow,35
- fmt$="########.########"
- IF ABS(x(j)) > 1E+07 OR ABS(x(j)) < .0001 THEN fmt$ = " +#.#######^^^^^"
- PRINT USING fmt$;x(j);
- LOCATE irow,57
- fmt$="########.########"
- IF ABS(y(j)) > 1E+07 OR ABS(y(j)) < .0001 THEN fmt$ = " +#.#######^^^^^"
- PRINT USING fmt$;y(j);
- irow=irow+1
- IF irow>23 THEN irow=23 : iatend=1
- COLOR fore1%,back1%,back1%
- WEND
- MathError:
- RESUME LoopStart
- END
-
- '---------------------------------------------------------------
- FUNCTION numfld# (rowfld%, colfld%, maxlen%, istatus%)
- '---------------------------------------------------------------
- 'returns double precision numeric input
- 'status contains number of characters input, 0 on ESC
- LOCATE rowfld%, colfld%, 1: PRINT SPACE$(maxlen%);
- LOCATE rowfld%, colfld%, 1
- ichar%=0 : iyflag%=0 : iexp=0
- notdone% = 1
- WHILE notdone% AND ichar% < maxlen%
- c% = ASC(INPUT$(1))
- ipass%=0
- IF ichar%=0 AND (c%=89 OR c%=121) THEN
- iyflag%=1
- ipass=1
- ELSEIF (ichar%=0 AND (c%=88 OR c%=120)) OR (ichar%=1 AND c%=61) THEN
- ipass%=1
- END IF
- IF (c%>=48 AND c%<=57) OR c%=45 OR c%=43 OR c%=46 OR ((c%=69 OR c%=101) AND iexp%=0) OR ipass%=1 THEN
- IF ipass%=0 THEN nfld$=nfld$+CHR$(c%)
- IF c%=69 OR c%=101 THEN iexp%=1
- LOCATE rowfld%,colfld%+ichar%,1: PRINT CHR$(c%);
- LOCATE rowfld%,colfld%+ichar%+1,1
- ichar%=ichar%+1
- ELSEIF (c%=10 OR c%=13 OR ichar%=maxlen%) AND ichar%>0 THEN
- notdone%=0
- ELSEIF c%=8 AND ichar%>0 THEN
- ichar%=ichar%-1
- IF ichar%=0 THEN iyflag%=0
- LOCATE rowfld%,colfld%+ichar%,1: PRINT CHR$(32);
- IF len(nfld$)>0 THEN nfld$=LEFT$(nfld$,LEN(nfld$)-1)
- LOCATE rowfld%,colfld%+ichar%,1:
- ELSEIF c%=27 THEN
- ichar%=0
- notdone%=0
- END IF
- WEND
- IF iyflag%=0 THEN istatus%=ichar% ELSE istatus%=-ichar%
- numfld#=0
- IF istatus%<>0 THEN numfld#=VAL(nfld$)
- endfn:
- END FUNCTION
-
- '---------------------------------------------------------------
- FUNCTION rtbis# (y#,dir%)
- '---------------------------------------------------------------
- 'root bisection routine
- 'dir%=0 starts at lowest partition, =1 at highest
- 'last chance is partition from XatYmin to XatYmax
- 'returns 0 upon failure to find root
- xacc#=1E-6*`XMEAN`
- xinc#=`XRANGE`/4.0
- FOR i%=0 TO 4
- IF i%=4 THEN
- x1#=`XATYMIN`
- x2#=`XATYMAX`
- ELSEIF dir%=1 THEN
- x2#=`XMAXIMUM`-xinc#*i%
- x1#=`XMAXIMUM`-xinc#*(i%+1)
- ELSE
- x1#=`XMINIMUM`+xinc#*i%
- x2#=`XMINIMUM`+xinc#*(i%+1)
- END IF
- f#=y#-`FNAME`((x1#))
- fmid#=y#-`FNAME`((x2#))
- IF f#*fmid#<0 THEN
- IF f#<0.0 THEN
- dx#=x2#-x1#
- rtb#=x1#
- ELSE
- dx#=x1#-x2#
- rtb#=x2#
- END IF
- FOR j%=1 TO 100
- dx#=dx#*0.5
- xmid#=rtb#+dx#
- fmid#=y#-`FNAME`((xmid#))
- IF fmid#<=0 THEN rtb#=xmid#
- IF ABS(dx#)<xacc# OR fmid#=0 THEN rtbis#=rtb# : GOTO done
- NEXT j%
- END IF
- NEXT i%
- rtbis#=0.0
- done:
- END FUNCTION
-
- !!QBASIC!!
- '---------------------------------------------------------------
- FUNCTION `FNAME`# (X#)
- '---------------------------------------------------------------
- ' TableCurve Function:`FILE` `DATE` `TIME`
- ' `TITLE`
- ' X= `XTITLE`
- ' Y= `YTITLE`
- ' Eqn# `EQNO` `EQSTR`
- ' r2=`R2VAL`
- ' r2adj=`R2ADJ`
- ' StdErr=`STDERR`
- ' Fval=`FVAL`
- ' a= `ASTR`
- ' b= `BSTR`
- ' c= `CSTR`
- ' d= `DSTR`
- ' e= `ESTR`
- ' f= `FSTR`
- ' g= `GSTR`
- ' h= `HSTR`
- ' i= `ISTR`
- ' j= `JSTR`
- ' k= `KSTR`
- '---------------------------------------------------------------------
- DIM cf#(11)`FPNRT`
- X#=`FX`
- N#=`FBAL2`
- N#=`FAUX`
- cf#(1)=`PBb`
- cf#(2)=`PBd`
- cf#(3)=`PBf`
- cf#(4)=`PBh`
- cf#(5)=`PBj`
- y1#=X#*evalpn(`ORDPB1`,X#,cf#())`LISTPB`
- cf#(1)=`PBa`
- cf#(2)=`PBc`
- cf#(3)=`PBe`
- cf#(4)=`PBg`
- cf#(5)=`PBi`
- cf#(6)=`PBk`
- y2#=evalpn(`ORDPB2`,N#,cf#())`LISTPB`
- Y#=y1#+y2#`LISTPB`
- cf#(1)=`RTa`
- cf#(2)=`RTc`
- cf#(3)=`RTe`
- cf#(4)=`RTg`
- cf#(5)=`RTi`
- cf#(6)=`RTk`
- ynum#=evalpn(`ORDRTN`,X#,cf#())`LISTRT`
- cf#(1)=`RTb`
- cf#(2)=`RTd`
- cf#(3)=`RTf`
- cf#(4)=`RTh`
- cf#(5)=`RTj`
- ydenom#=evalpn(`ORDRTD`,X#,cf#())`LISTRT`
- Y#=ynum#/(1.0+X#*ydenom#)`LISTRT`
- cf#(1)= `PNa`
- cf#(2)= `PNb`
- cf#(3)= `PNc`
- cf#(4)= `PNd`
- cf#(5)= `PNe`
- cf#(6)= `PNf`
- cf#(7)= `PNg`
- cf#(8)= `PNh`
- cf#(9)= `PNi`
- cf#(10)=`PNj`
- cf#(11)=`PNk`
- Y#=evalpn(`ORDPN`,X#,cf#())`LISTPN`
- X1#=`F1`
- X2#=`F2`
- X3#=`F3`
- X4#=`F4`
- Y#=`EQNCODE`
- `FNAME`#=`FY`
- END FUNCTION
-
- '---------------------------------------------------------------`FPNRT`
- FUNCTION evalpn# (order%, x#, cf#())`FPNRT`
- '---------------------------------------------------------------`FPNRT`
- 'Polynomial Calculation Function`FPNRT`
- 'Passed Array `SCOPE` must be dimensioned to 11`FPNRT`
- ypn#=cf#(order%+1)`FPNRT`
- FOR iter%=order% TO 1 STEP -1`FPNRT`
- ypn#= ypn#*x#+cf#(iter%)`FPNRT`
- NEXT iter%`FPNRT`
- evalpn#=ypn#`FPNRT`
- END FUNCTION`FPNRT`
-
- '---------------------------------------------------------------`ERF`
- FUNCTION ERF#(x#)`ERF`
- '---------------------------------------------------------------`ERF`
- z=ABS(x)`ERF`
- t=1.0/(1.0+0.5*z)`ERF`
- ans=t*(-1.13520398#+t*(1.48851587#+t*(-.82215223#+t*.17087277#)))`ERF`
- ans=t*(.09678418#+t*(-.18628806#+t*(.27886807#+ans)))`ERF`
- ans=(t*EXP(-z*z-1.26551223#+t*(1.00002368#+t*(.37409196#+ans))))`ERF`
- IF x >= 0! THEN ERF#=1.0-ans ELSE ERF#=-1.0+ans`ERF`
- END FUNCTION`ERF`
-
- !!QBASIC!!
- ~~QBASIC~~
-