home *** CD-ROM | disk | FTP | other *** search
- ~~PASCAL~~
- {---------------------------------------------------------------}
- { TableCurve Pascal Library Module }
- {---------------------------------------------------------------}
- { Although the full calling routine for the TableCode }
- { functions is specific to the Borland Turbo-Pascal compiler, }
- { the code has been written for portability using standard }
- { BIOS/DOS system calls. Only the system interrupt function }
- { intr(), the system registers Regs in the DOS unit, and the }
- { compiler directives are likely to be compiler-dependent. }
- {---------------------------------------------------------------}
- { The generated code uses the full 10 byte precision of the }
- { extended real type if a math co-processor is installed or if }
- { using version 5.0+. Version 4.0 without a math co-processor }
- { uses the default 6 byte real. }
- {---------------------------------------------------------------}
- { NOTE: With the N+ directive, you are limited to Turbo }
- { Pascal's 8-level 8087 stack. Most higher order rational }
- { and polynomial equations, if coded onto a single line, will }
- { overflow this stack. For this reason, the function evalpn() }
- { is used to evaluate all polynomial expressions. }
- {---------------------------------------------------------------}
-
- program _`FILENOEX`;
-
- {$IFDEF VER40}
- {$IFDEF CPU87}
- {$N+} { v4.0, 80x87 10 byte extended real }
- {$ELSE}
- {$N-} { v4.0, default 6 byte real }
- {$ENDIF}
- {$ELSE}
- {$IFDEF CPU87}
- {$N+,E-} { v5.0+, 10 byte extended real, 80x87 in-line }
- {$ELSE}
- {$N+,E+} { v5.0+, 10 byte extended real, emulation on }
- {$ENDIF}
- {$ENDIF}
-
- {$M 8192,0,65536} { Set stack=8K, Heap=64K }
-
- uses Dos;
-
- type
- {$IFOPT N+}
- real = extended; { use 10 byte floating point w/80x87 }
- {$ENDIF}
- coef= array[0..10] of real;
- xyvar= array[0..16] of real;
-
- var
- x,y : xyvar;
- i,j,irow,gooddata,dir,atmax : integer;
- attr0,attr1,attr2 : integer;
- iscolor : integer;
- strtmp : string[80];
-
- !!PASCAL!!
- type`SCOPE`
- coef= array[0..10] of real;`SCOPE`
-
- {---------------------------------------------------------------}`FPNRT`
- function evalpn (order: integer; var x: real; var c: coef) : real;`FPNRT`
- {---------------------------------------------------------------}`FPNRT`
- var i: integer;`FPNRT`
- y : real;`FPNRT`
- begin`FPNRT`
- y := c[order];`FPNRT`
- for i := order-1 downto 0 do`FPNRT`
- y := y*x+c[i];`FPNRT`
- evalpn :=y;`FPNRT`
- end;`FPNRT`
-
- {---------------------------------------------------------------}`ERF`
- function Erf ( x: real) : real;`ERF`
- {---------------------------------------------------------------}`ERF`
- var t,z,ans : real;`ERF`
- begin`ERF`
- z:=Abs(x);`ERF`
- t:=1.0/(1.0+0.5*z);`ERF`
- ans:=(t*exp(-z*z-1.26551223+t*(1.00002368+t*(0.37409196+t*(0.09678418+`ERF`
- t*(-0.18628806+t*(0.27886807+t*(-1.13520398+t*(1.48851587+`ERF`
- t*(-0.82215223+t*0.17087277))))))))));`ERF`
- Erf := 1.0-ans;`ERF`
- if x<0 then`ERF`
- Erf := -1.0+ans;`ERF`
- end;`ERF`
-
- {---------------------------------------------------------------}`POW`
- function Pow ( x,n : real) : real;`POW`
- {---------------------------------------------------------------}`POW`
- begin`POW`
- Pow := Exp(n*Ln(x));`POW`
- end;`POW`
-
- {---------------------------------------------------------------}
- function `FNAME` (x: real) :real;
- {---------------------------------------------------------------}
- { TableCurve Function:`FILE` `DATE` `TIME` }
- { `TITLE` }
- { X= `XTITLE` }
- { Y= `YTITLE` }
- { Eqn# `EQNO` `EQSTR` }
- { r2=`R2VAL` }
- { r2adj=`R2ADJ` }
- { StdErr=`STDERR` }
- { Fstat=`FVAL` }
- { a= `ASTR` }
- { b= `BSTR` }
- { c= `CSTR` }
- { d= `DSTR` }
- { e= `ESTR` }
- { f= `FSTR` }
- { g= `GSTR` }
- { h= `HSTR` }
- { i= `ISTR` }
- { j= `JSTR` }
- { k= `KSTR` }
- var `FLIST` : real;
- var y : real;
- var c1,c2 : coef;`LISTRT`
- var c1,c2 : coef;`LISTPB`
- var c : coef;`LISTPN`
- var n : real;`FDECLN`
- begin
- x :=`FX`;
- n :=`FBAL2`;
- n :=`FAUX`;
- c1[0] := `PBb`;
- c1[1] := `PBd`;
- c1[2] := `PBf`;
- c1[3] := `PBh`;
- c1[4] := `PBj`;
- c2[0] := `PBa`;
- c2[1] := `PBc`;
- c2[2] := `PBe`;
- c2[3] := `PBg`;
- c2[4] := `PBi`;
- c2[5] := `PBk`;
- y := x*evalpn(`ORDPB1`,x,c1)+evalpn(`ORDPB2`,n,c2);`LISTPB`
- c1[0] := `RTa`;
- c1[1] := `RTc`;
- c1[2] := `RTe`;
- c1[3] := `RTg`;
- c1[4] := `RTi`;
- c1[5] := `RTk`;
- c2[0] := `RTb`;
- c2[1] := `RTd`;
- c2[2] := `RTf`;
- c2[3] := `RTh`;
- c2[4] := `RTj`;
- y := evalpn(`ORDRTN`,x,c1)/(1.0+x*evalpn(`ORDRTD`,x,c2));`LISTRT`
- c[0] := `PNa`;
- c[1] := `PNb`;
- c[2] := `PNc`;
- c[3] := `PNd`;
- c[4] := `PNe`;
- c[5] := `PNf`;
- c[6] := `PNg`;
- c[7] := `PNh`;
- c[8] := `PNi`;
- c[9] := `PNj`;
- c[10]:= `PNk`;
- y := (evalpn(`ORDPN`,x,c));`LISTPN`
- x1 :=`F1`;
- x2 :=`F2`;
- x3 :=`F3`;
- x4 :=`F4`;
- y :=`EQNCODE`;
- `FNAME` :=`FY`;
- end;
- !!PASCAL!!
-
- {---------------------------------------------------------------}
- function rtbis (y: real; dir: integer) :real;
- {---------------------------------------------------------------}
- { root bisection routine }
- { dir=0 starts at lowest partition, dir=1 starts at highest partition }
- { last chance is partition from XatYmin to XatYmax }
- { returns 0 upon failure to find root }
- var j : integer;
- x1,x2,xinc,dx,f,fmid,xmid,rtb,xacc,inc : real;
- begin
- rtbis := 0.0;
- xacc := 1E-6*`XMEAN`; { convergence limit }
- xinc := `XRANGE`/4.0;
- inc := 0.0;
- while inc<5.0 do { X range divided into 4 partitions }
- begin
- if inc=4.0 then
- begin
- x1 := `XATYMIN`;
- x2 := `XATYMAX`;
- end;
- if(inc<4.0) then
- begin
- if dir>0 then
- begin
- x2 := `XMAXIMUM`-xinc*inc;
- x1 := `XMAXIMUM`-xinc*(inc+1.0);
- end;
- if dir=0 then
- begin
- x1 := `XMINIMUM`+xinc*inc;
- x2 := `XMINIMUM`+xinc*(inc+1.0);
- end;
- end;
- f := y-`FNAME`(x1);
- fmid := y-`FNAME`(x2);
- if f*fmid<0 then
- begin
- if f<0.0 then
- begin
- dx := x2-x1;
- rtb := x1;
- end;
- if f>=0 then
- begin
- dx := x1-x2;
- rtb := x2;
- end;
- j := 1;
- while j<101 do
- begin
- dx := dx*0.5;
- xmid := rtb+dx;
- fmid := y-`FNAME`(xmid);
- if fmid<=0 then
- rtb := xmid;
- if (Abs(dx)<xacc) or (fmid=0.0) then
- begin
- rtbis :=rtb;
- j :=101;
- inc :=5.0;
- end;
- j := j+1;
- end;
- end;
- inc := inc+1;
- end;
- end;
-
- {---------------------------------------------------------------}
- procedure cursor( row, col : integer);
- {---------------------------------------------------------------}
- var { sets cursor at row, col (0,0 = origin) }
- Regs : registers;
- begin
- with Regs do
- begin
- AH := 2;
- BH := 0;
- DH := row;
- DL := col;
- Intr($10,regs);
- end;
- end;
-
- {---------------------------------------------------------------}
- function getattr : integer;
- {---------------------------------------------------------------}
- var { gets current screen attribute }
- regs : registers;
- begin
- with Regs do
- begin
- AH := 8;
- BH := 0;
- Intr($10,regs);
- getattr := AH;
- end;
- end;
-
- {---------------------------------------------------------------}
- function getcolor : integer;
- {---------------------------------------------------------------}
- var { returns 1 for color display, 0 for monochrome }
- regs : registers;
- begin
- with Regs do
- begin
- AH := 15;
- Intr($10,regs);
- getcolor := 1;
- if ((AL=0) or (AL=2) or (AL=7)) then getcolor := 0;
- end;
- end;
-
- {---------------------------------------------------------------}
- procedure cls( attr : integer);
- {---------------------------------------------------------------}
- var { clears screen with attribute, cursor to 0,0 }
- regs : registers;
- begin
- with Regs do
- begin
- AH := 6;
- AL := 0;
- BH := attr;
- CH := 0;
- CL := 0;
- DH := 24;
- DL := 79;
- Intr($10,regs);
- cursor(0,0);
- end;
- end;
-
- {---------------------------------------------------------------}
- procedure clsblk( top, left, btm, right, attr : integer);
- {---------------------------------------------------------------}
- var { clears screen block, cursor inside }
- regs : registers;
- begin
- with Regs do
- begin
- AH := 6;
- AL := 0;
- BH := attr;
- CH := top;
- CL := left;
- DH := btm;
- DL := right;
- Intr($10,regs);
- cursor(top+1,left+1);
- end;
- end;
-
- {---------------------------------------------------------------}
- procedure pca( c, attr, row, col : integer);
- {---------------------------------------------------------------}
- var { prints character, atribute to screen }
- regs : registers;
- begin
- cursor(row,col);
- with Regs do
- begin
- AH := 9;
- AL := ORD(c);
- BH := 0;
- BL := attr;
- CX := 1;
- Intr($10,regs);
- end;
- end;
-
- {---------------------------------------------------------------}
- procedure psa( strv : string; attr, row, col : integer);
- {---------------------------------------------------------------}
- var { prints string with attribute to screen }
- i,len : integer;
- begin
- for i := 1 to Length(strv) do
- begin
- pca(Ord(strv[i]),attr,row,col);
- col := col +1;
- end;
- end;
-
- {---------------------------------------------------------------}
- function getch : integer;
- {---------------------------------------------------------------}
- var { character input, returns 256+code for FnKey }
- regs : registers;
- fnadd : integer;
- begin
- fnadd := 0;
- with Regs do
- begin
- AX := $700;
- Intr($21,regs);
- if AL=0 then
- begin
- AX := $700;
- Intr($21,regs);
- fnadd :=256;
- end;
- getch := AL + fnadd;
- end;
- end;
-
- {---------------------------------------------------------------}
- procedure setwin(
- trow : integer; { top row of window }
- lcol : integer; { left column of window }
- brow : integer; { bottom row of window }
- rcol : integer; { right column of window }
- attr : integer; { color attribute }
- border : integer; { 1=single 2=double border }
- title : string); { window's main title }
- {---------------------------------------------------------------}
- var { sets simple window on screen }
- tl, tr, bl, br, lr, tb : integer; { 6 border characters }
- i,xcntr,len : integer;
-
- begin
- clsblk(trow,lcol,brow,rcol,attr);
- tl:=218; tr:=191; bl:=192; br:=217; lr:=196; tb:=179; { Single Border }
- if border=2 then
- begin { Double Border }
- tl:=201; tr:=187; bl:=200; br:=188; lr:=205; tb:=186;
- end;
- pca(tl,attr,trow,lcol);
- pca(bl,attr,brow,lcol);
- pca(tr,attr,trow,rcol);
- pca(br,attr,brow,rcol);
- for i := lcol+1 to rcol-1 do
- begin
- pca(lr,attr,trow,i);
- pca(lr,attr,brow,i);
- end;
- for i := trow+1 to brow-1 do
- begin
- pca(tb,attr,i,lcol);
- pca(tb,attr,i,rcol);
- end;
- xcntr := (rcol+lcol-Length(title)) div 2;
- psa(title,attr,trow,xcntr);
- end;
-
- {---------------------------------------------------------------}
- function numfld(
- var realval : real; { numeric input value }
- row : integer; { screen row to begin input }
- col : integer; { screen column to begin input }
- maxlen : integer; { maximum length of input string, (<41) }
- attr : integer) { color attribute for entry field }
- : integer;
- {---------------------------------------------------------------}
- var
- fld : string[40];
- i,j,c,yflag,expflag,pass : integer;
- done : boolean;
-
- begin
- for j :=0 to maxlen-1 do
- pca(32,attr,row,col+j);
- for j :=1 to maxlen do
- fld[j] := ' ';
- fld[j] :=Chr(0);
- cursor(row,col);
- i := 0;
- j := 0;
- yflag := 0;
- expflag := 0;
- done := False;
- repeat
- c := getch;
- pass := 0;
- if i=0 then
- begin
- if (c=89) or (c=121) then
- begin
- yflag := 1;
- pass := 1;
- end
- else if (c=88) or (c=120) then
- pass :=1;
- end;
- if (i=1) and (c=61) then
- pass := 1;
- if(((c>=48) and (c<=57)) or (c=45) or (c=43) or (c=46) or
- (((c=69) or (c=101)) and (expflag=0)) or (pass=1)) then
- begin
- pca(c,attr,row,col+i);
- cursor(row,col+i+1);
- i := i+1;
- if pass=0 then
- begin
- fld[j+1] := Chr(c);
- j := j+1;
- end;
- if (c=69) or (c=101) then
- expflag := 1;
- end;
- if(((c=10) or (c=13) or (i=maxlen)) and (i>0)) then done := True;
- if((c=8) and (i>0)) then
- begin
- i := i-1;
- pca(32,attr,row,col+i);
- if i=0 then
- yflag := 0;
- if j<>0 then
- begin
- j := j-1;
- fld[j+1] := ' ';
- end;
- end;
- if c=27 then
- begin
- i := 0;
- done := True;
- end;
- until done;
- numfld := j;
- fld[0] := Chr(j);
- if yflag=1 then numfld := -j;
- Val(fld,realval,i); { convert string to real }
- if(i<>0) then realval :=0; { set to 0 if invalid conversion }
- end;
-
- {---------------------------------------------------------------}
-
- begin
- attr0 := getattr; { screen attribute at startup }
- iscolor := getcolor; { video mode for color flag }
- if iscolor=1 then
- begin
- attr1 := 1 + 16 * 7; { main window attribute }
- attr2 := 15+ 16 * 1; { xy data window attribute }
- end
- else
- begin
- attr1 := 15 + 16 * 0; { main window attribute }
- attr2 := 0 + 16 * 7; { xy data window attribute }
- end;
- cls(attr1);
-
- strtmp :=
- ' TableCurve Function: `FILE` `DATE` `TIME` ';
- setwin(0,1,24,78,attr1,2,strtmp); { main window }
- strtmp := ' `TITLE` ';
- setwin(4,32,23,76,attr2,1,strtmp); { x-y data window }
- psa('`XTITLE`',attr2,5,34);
- psa('`YTITLE`',attr2,5,56);
-
- psa('`EQSTR`',attr1,2,3); { equation data summary }
- psa('Eqn# `EQNO`',attr1,3,5);
- psa('r2=`R2VAL`',attr1,4,5);
- psa('a= `ASTR`',attr1,5,5);
- psa('b= `BSTR`',attr1,6,5);
- psa('c= `CSTR`',attr1,7,5);
- psa('d= `DSTR`',attr1,8,5);
- psa('e= `ESTR`',attr1,9,5);
- psa('f= `FSTR`',attr1,10,5);
- psa('g= `GSTR`',attr1,11,5);
- psa('h= `HSTR`',attr1,12,5);
- psa('i= `ISTR`',attr1,13,5);
- psa('j= `JSTR`',attr1,14,5);
- psa('k= `KSTR`',attr1,15,5);
- psa('X= `XTITLE`',attr1,17,3);
- psa('Y= `YTITLE`',attr1,18,3);
- psa('Enter Value [x=,y=]',attr1,20,3);
- psa('Press Esc to End Program',attr1,23,3);
-
- irow :=6;
- atmax :=0;
- repeat
- j := irow-6;
- gooddata := numfld(x[j],21,3,25,attr2); { numeric input procedure }
- if gooddata=0 then
- begin
- cls(attr0);
- Exit;
- end
- else
- begin
- clsblk(21,3,21,30,attr1); { clear data entry position }
- if irow=22 then clsblk(22,33,22,75,attr2); { clr row at btm }
- if(gooddata>=0) then
- y[j] := `FNAME`(x[j]); { TableCode eqn call }
- if(gooddata<0) then
- begin
- y[j] := x[j];
- if dir=0 then dir :=1 else dir :=0;
- x[j] :=rtbis(y[j],dir);
- end;
- if (Abs(x[j])>1E+08) or (Abs(x[j])<1E-08)
- then Str(x[j]:17:-8,strtmp)
- else Str(x[j]:17:8,strtmp);
- psa(strtmp,attr2,irow,34); { print x-value }
- if (Abs(y[j])>1E+08) or (Abs(y[j])<1E-08)
- then Str(y[j]:17:-8,strtmp)
- else Str(y[j]:17:8,strtmp);
- psa(strtmp,attr2,irow,56); { print y-value }
- irow := irow +1;
- if irow>22 then
- begin
- irow :=22; { overwrite at btm of window }
- atmax :=1;
- end;
- end;
- until irow=0; { only exit from loop is ESC }
- end.
- ~~PASCAL~~
-