home *** CD-ROM | disk | FTP | other *** search
- ~~FORTRAN~~
- *----------------------------------------------------------*
- * TableCurve FORTRAN Library Module
- *----------------------------------------------------------*
- * Although the full calling routine for the TableCode
- * subroutine is specific to the Lahey F77L Compilers, the
- * code has been written for portability using standard
- * FORTRAN 77. Only the system interrupt function INTRUP and
- * the system registers intreg(9) [INTEGER*2 AX,BX,CX,DX,DS,
- * ES,DI,SI,flags] are likely to be compiler-dependent.
- *----------------------------------------------------------*
- * Certain code lines use Lahey routines OVEFL, UNDFL, DVCHK,
- * and INVALOP to mask exceptions from arithmetic overflow,
- * underflow, divide-by-zero, and invalid operations. These
- * lines are commented out but can be activated if such
- * masking is desired on a Lahey compiler.
- *----------------------------------------------------------*
-
- *----------------------------------------------------------*
- PROGRAM main
- *----------------------------------------------------------*
- INTEGER *2 irow,j,dataok
- INTEGER *2 attr0,attr1,attr2,lenstr,idir
- LOGICAL iscolor
- DOUBLE PRECISION x(17),y(17)
- CHARACTER tempstr*60,t2*80
-
- ***** ----------- Lahey Exception Routines ----------- *****
- ***** LOGICAL*1 lflag(4)
- ***** CALL ovefl(lflag(1))
- ***** CALL dvchk(lflag(2))
- ***** CALL undfl(lflag(3))
- ***** CALL invalop(lflag(4))
- ***** ------------------------------------------------ *****
-
- ***** Get DOS Attr, Assign 2 Window Attr, Clear Screen
- CALL getattr(attr0)
- CALL getcolor(iscolor)
- IF (iscolor) THEN
- attr1= 1 + 7*16
- attr2= 15+ 1*16
- ELSE
- attr1=15+ 0*16
- attr2=0 + 7*16
- ENDIF
- CALL cls(attr1)
-
- ***** Main Screen Window Uses 1st Attr, Double Border
- CALL strclr(t2)
- t2='TableCurve `FILE` `DATE` `TIME`'
- CALL str0(t2,lenstr)
- CALL window(0,1,24,78,attr1,2,t2)
- CALL strclr(t2)
-
- ***** X-Y Data Window Uses 2nd Attribute, Single Border
- CALL strclr(tempstr)
- tempstr=' `TITLE` '
- CALL str0(tempstr,lenstr)
- CALL window(4,32,23,76,attr2,1,tempstr)
- CALL strclr(tempstr)
- tempstr='`XTITLE`'
- CALL strwrtmp(tempstr,attr2,5,34)
- tempstr='`YTITLE`'
- CALL strwrtmp(tempstr,attr2,5,56)
-
- ***** Equation Data Summary
- tempstr='`EQSTR`'
- CALL strwrtmp(tempstr,attr1,2,3)
- tempstr='Eqn# `EQNO`'
- CALL strwrtmp(tempstr,attr1,3,5)
- tempstr='r2=`R2VAL`'
- CALL strwrtmp(tempstr,attr1,4,5)
- tempstr='a= `ASTR`'
- CALL strwrtmp(tempstr,attr1,5,5)
- tempstr='b= `BSTR`'
- CALL strwrtmp(tempstr,attr1,6,5)
- tempstr='c= `CSTR`'
- CALL strwrtmp(tempstr,attr1,7,5)
- tempstr='d= `DSTR`'
- CALL strwrtmp(tempstr,attr1,8,5)
- tempstr='e= `ESTR`'
- CALL strwrtmp(tempstr,attr1,9,5)
- tempstr='f= `FSTR`'
- CALL strwrtmp(tempstr,attr1,10,5)
- tempstr='g= `GSTR`'
- CALL strwrtmp(tempstr,attr1,11,5)
- tempstr='h= `HSTR`'
- CALL strwrtmp(tempstr,attr1,12,5)
- tempstr='i= `ISTR`'
- CALL strwrtmp(tempstr,attr1,13,5)
- tempstr='j= `JSTR`'
- CALL strwrtmp(tempstr,attr1,14,5)
- tempstr='k= `KSTR`'
- CALL strwrtmp(tempstr,attr1,15,5)
-
- ***** Data Entry Setup
- tempstr='X= `XTITLE`'
- CALL strwrtmp(tempstr,attr1,17,3)
- tempstr='Y= `YTITLE`'
- CALL strwrtmp(tempstr,attr1,18,3)
- tempstr='Enter Value [x=,y=]'
- CALL strwrtmp(tempstr,attr1,20,3)
- tempstr='Press Esc to End Program'
- CALL strwrtmp(tempstr,attr1,23,3)
-
- ***** Data Entry Loop Rows 5-21
- irow=6
- idir=0
- 10 j=irow-5
- dataok=1
- IF (idir.EQ.1) THEN
- idir=0
- ELSE
- idir=1
- ENDIF
- ***** Data Entry Routine for X-Value
- CALL numfld(tempstr,21,3,25,attr2,dataok)
- ***** dataok=0 on ESCAPE -- This is only exit from loop
- IF (dataok.EQ.0) THEN
- CALL cls(attr0)
- GO TO 40
- ENDIF
- IF (dataok.GT.0) THEN
- READ(tempstr,20) x(j)
- 20 FORMAT(F25.0)
- CALL strclr(tempstr)
- CALL `FNAME`(x(j),y(j))
- ELSE
- READ(tempstr,20) y(j)
- CALL strclr(tempstr)
- CALL rtbis(y(j),idir,x(j))
- ENDIF
-
- ***** ------ Check Exceptions Code ------------------- *****
- ***** CALL ovefl(lflag(1))
- ***** CALL dvchk(lflag(2))
- ***** CALL undfl(lflag(3))
- ***** CALL invalop(lflag(4))
- ***** IF (lflag(1).OR.lflag(2).OR.lflag(3).OR.lflag(4)) THEN
- ***** lflag(1)=.FALSE.
- ***** lflag(2)=.FALSE.
- ***** lflag(3)=.FALSE.
- ***** lflag(4)=.FALSE.
- ***** CALL clsblk(irow,34,irow,52,attr2)
- ***** GO TO 10
- ***** ENDIF
- ***** ------------------------------------------------ *****
-
- IF(irow.EQ.22) THEN
- CALL clsblk(22,33,22,75,attr2)
- ENDIF
- ***** Convert x,y to Formatted Strings For Output to Table *****
- WRITE(tempstr,30) x(j)
- 30 FORMAT(G18.12)
- CALL strwrtmp(tempstr,attr2,irow,34)
- WRITE(tempstr,30) y(j)
- CALL strwrtmp(tempstr,attr2,irow,56)
- irow=irow+1
- IF (irow.GT.22) THEN
- irow=22
- ENDIF
- GO TO 10
-
- ***** End of Data Entry Loop *******************************
- 40 CALL cls(attr0)
- END
-
- *----------------------------------------------------------*
- SUBROUTINE cursor(row,col)
- ***** Sets Cursor Position (0,0=Origin)
- ***** AH=2,BH=0 DH,DL=row,col INT 10H
- *----------------------------------------------------------*
- INTEGER*2 row,col
- INTEGER*2 intreg(9)
- intreg(1)=2*256
- intreg(2)=0
- intreg(4)=row*256+col
- CALL INTRUP(intreg,16)
- RETURN
- END
-
- *----------------------------------------------------------*
- SUBROUTINE getattr(attr)
- ***** Retrieves Current Screen Attribute
- ***** AH=8,BH=0,INT 10H AH contains attribute
- *----------------------------------------------------------*
- INTEGER*2 attr
- INTEGER*2 intreg(9)
- intreg(1)=8*256
- intreg(2)=0
- CALL INTRUP(intreg,16)
- attr=intreg(1)/256
- RETURN
- END
-
- *----------------------------------------------------------*
- SUBROUTINE getcolor(type)
- ***** Returns .TRUE. for color mode, .FALSE. for monochrome
- ***** AH=15 INT 10H AL contains video mode
- *----------------------------------------------------------*
- LOGICAL type
- INTEGER*2 mode
- INTEGER*2 intreg(9)
- intreg(1)=15*256
- CALL INTRUP(intreg,16)
- mode=I2MOD(intreg(1),256)
- type=.TRUE.
- IF (mode.EQ.0 .OR. mode.EQ.2 .OR. mode.EQ.7) type=.FALSE.
- RETURN
- END
-
- *----------------------------------------------------------*
- SUBROUTINE cls(attr)
- ***** Clears Screen w/Attribute, Sets Cursor To Origin
- ***** AH=6,BH=attribute CH,CL,DH,DL=coord(0,0,24,79) INT 10H
- *----------------------------------------------------------*
- INTEGER*2 attr
- INTEGER*2 intreg(9)
- intreg(1)=6*256
- intreg(2)=attr*256
- intreg(3)=0
- intreg(4)=24*256+79
- CALL INTRUP(intreg,16)
- CALL cursor(0,0)
- RETURN
- END
-
- *----------------------------------------------------------*
- SUBROUTINE clsblk(top,left,btm,right,attr)
- ***** Clears Part of Screen w/Attribute, Cursor Inside
- ***** AH=6,BH=attribute CH,CL,DH,DL=coord(t,l,b,r) INT 10H
- *----------------------------------------------------------*
- INTEGER*2 top,left,btm,right,attr
- INTEGER*2 intreg(9)
- intreg(1)=6*256
- intreg(2)=attr*256
- intreg(3)=top*256+left
- intreg(4)=btm*256+right
- CALL INTRUP(intreg,16)
- CALL cursor(top+1,left+1)
- RETURN
- END
-
- *----------------------------------------------------------*
- SUBROUTINE pca(c,attr,row,col)
- ***** Write Character w/Attribute at Row,Col
- ***** AH=9,AL=char BH=0 BL=attr CX=1 INT 10H
- *----------------------------------------------------------*
- INTEGER*2 c,attr,row,col
- INTEGER*2 intreg(9)
- CALL cursor(row,col)
- intreg(1)=9*256+c
- intreg(2)=attr
- intreg(3)=1
- CALL INTRUP(intreg,16)
- RETURN
- END
-
- *----------------------------------------------------------*
- SUBROUTINE psa(str,attr,row,col)
- ***** Write String w/Attribute at Row,Col
- *----------------------------------------------------------*
- CHARACTER str*80
- INTEGER*2 attr,row,col
- INTEGER*2 i,ci
- INTEGER cint
- DO 10 i=1,80
- CALL cursor(row,col)
- cint=ICHAR(str(i:i))
- IF (cint.EQ.0) GO TO 20
- ci=cint
- CALL pca(ci,attr,row,col)
- col=col+1
- 10 CONTINUE
- 20 RETURN
- END
-
- *----------------------------------------------------------*
- SUBROUTINE str0(str,lenstr)
- ***** Null Terminate String, Return Length in len
- *----------------------------------------------------------*
- CHARACTER str*(*)
- INTEGER*2 lenstr
- INTEGER i,ilen,j
- ilen=LEN(str)
- DO 10 i=ilen,1,-1
- j=ICHAR(str(i:i))
- IF (j .NE. 32 .AND. j .NE. 0) GO TO 20
- 10 CONTINUE
- 20 str(i+1:i+1)=CHAR(0)
- lenstr=i
- RETURN
- END
-
- *----------------------------------------------------------*
- SUBROUTINE strclr(str)
- ***** Clear String to Blanks
- *----------------------------------------------------------*
- CHARACTER str*(*)
- INTEGER i,ilen
- ilen=LEN(str)
- DO 10 i=1,ilen
- str(i:i)=CHAR(32)
- 10 CONTINUE
- RETURN
- END
-
- *----------------------------------------------------------*
- SUBROUTINE strwrtmp(str,attr,row,col)
- ***** Prepare string, write @row,col, clear to blanks
- *----------------------------------------------------------*
- CHARACTER str*(*)
- INTEGER*2 lenstr
- CALL str0(str,lenstr)
- CALL psa(str,attr,row,col)
- CALL strclr(str)
- RETURN
- END
-
- *----------------------------------------------------------*
- SUBROUTINE getch(c)
- ***** DOS Get Character AX=700H, INT 21H, Char in AL
- ***** Returns Character as INTEGER*2 [Fn Keys are +256]
- *----------------------------------------------------------*
- INTEGER*2 c
- INTEGER*2 intreg(9)
- intreg(1)=1792
- CALL INTRUP(intreg,33)
- c=I2MOD(intreg(1),256)
- IF(c.EQ.0) THEN
- intreg(1)=1792
- CALL INTRUP(intreg,33)
- c=256+I2MOD(intreg(1),256)
- ENDIF
- RETURN
- END
-
- *----------------------------------------------------------*
- SUBROUTINE window(trow,lcol,brow,rcol,attr,border,title)
- ***** Simple Window, Border, Title
- *----------------------------------------------------------*
- INTEGER*2 trow,lcol,brow,rcol,attr,border
- INTEGER*2 tl,tr,bl,br,lr,tb
- INTEGER*2 i,lentitle
- CHARACTER title*(*)
-
- CALL clsblk(trow,lcol,brow,rcol,attr)
- IF(border.EQ.1) THEN
- tl=218
- tr=191
- bl=192
- br=217
- lr=196
- tb=179
- ELSE
- tl=201
- tr=187
- bl=200
- br=188
- lr=205
- tb=186
- ENDIF
- CALL pca(tl,attr,trow,lcol)
- CALL pca(bl,attr,brow,lcol)
- CALL pca(tr,attr,trow,rcol)
- CALL pca(br,attr,brow,rcol)
- DO 10 i=lcol+1,rcol-1
- CALL pca(lr,attr,trow,i)
- CALL pca(lr,attr,brow,i)
- 10 CONTINUE
- DO 20 i=trow+1,brow-1
- CALL pca(tb,attr,i,lcol)
- CALL pca(tb,attr,i,rcol)
- 20 CONTINUE
- CALL str0(title,lentitle)
- CALL psa(title,attr,trow,(rcol+lcol)/2-lentitle/2)
- RETURN
- END
-
- *----------------------------------------------------------*
- SUBROUTINE numfld(fld,row,col,maxlen,attr,status)
- ***** Simple Numeric Field Input
- ***** status is set to 0 on ESCAPE
- *----------------------------------------------------------*
- CHARACTER fld*(*)
- INTEGER*2 row,col,maxlen,attr,status
- INTEGER*2 i,j,c,yflag,expflag,pass
- INTEGER ch
-
- CALL strclr(fld)
- DO 10 j=0,maxlen-1
- CALL pca(32,attr,row,col+j)
- 10 CONTINUE
- CALL cursor(row,col)
- i=0
- j=0
- expflag=0
- yflag=0
- 20 CALL getch(c)
- pass=0
- IF(i.EQ.0 .AND. (c.EQ.89 .OR. c.EQ.121)) THEN
- yflag=1
- pass=1
- ELSE IF(i.EQ.0 .AND. (c.EQ.88 .OR. c.EQ.120)) THEN
- pass=1
- ELSE IF(i.EQ.1 .AND. c.EQ.61) THEN
- pass=1
- ENDIF
- IF((c.GE.48 .AND. c.LE.57) .OR. c.EQ.45 .OR. c.EQ.43
- 1 .OR. c.EQ.46 .OR. ((c.EQ.69 .OR. c.EQ.101).AND.expflag.EQ.0)
- 2 .OR. pass.EQ.1) THEN
- ch=c
- CALL pca(c,attr,row,col+i)
- CALL cursor(row,col+i+1)
- i=i+1
- IF (pass.EQ.0) THEN
- fld(j+1:j+1)=CHAR(ch)
- j=j+1
- ENDIF
- IF(c.EQ.69 .OR. c.EQ.101) THEN
- expflag=1
- ENDIF
- ELSE IF((c.EQ.10 .OR. c.EQ.13 .OR. i.EQ.maxlen)
- 1 .AND. i.NE.0) THEN
- GO TO 30
- ELSE IF(c.EQ.8 .AND. i.GT.0) THEN
- i=i-1
- CALL pca(32,attr,row,col+i)
- IF (i.EQ.0) THEN
- yflag=0
- ENDIF
- IF (j.NE.0) THEN
- j=j-1
- fld(j+1:j+1)=CHAR(0)
- ENDIF
- ELSE IF(c.EQ.27) THEN
- i=0
- GO TO 30
- ENDIF
- IF(i.LT.maxlen) GO TO 20
- 30 fld(j+1:j+1)=CHAR(0)
- IF (yflag.EQ.1) THEN
- status=-j
- ELSE
- status=j
- ENDIF
- 40 RETURN
- END
-
- *----------------------------------------------------------*
- SUBROUTINE rtbis(y,dir,x)
- ***** 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
- *----------------------------------------------------------*
- INTEGER*2 dir,i,j
- DOUBLE PRECISION y,x,x1,x2,y2,xinc,dx,f,fmid,xmid,rtb,xacc
- xacc=1E-6*`XMEAN`
- xinc=`XRANGE`/4.0
- DO 10 i=0,4
- IF (i.EQ.4) THEN
- x1=`XATYMIN`
- x2=`XATYMAX`
- ELSE IF (dir.EQ.1) THEN
- x2=`XMAXIMUM`-xinc*i
- x1=`XMAXIMUM`-xinc*(i+1)
- ELSE
- x1=`XMINIMUM`+xinc*i
- x2=`XMINIMUM`+xinc*(i+1)
- ENDIF
- CALL `FNAME`(x1,y2)
- f=y-y2
- CALL `FNAME`(x2,y2)
- fmid=y-y2
- IF ((f*fmid).LT.0) THEN
- IF (f.LT.0.0) THEN
- dx=x2-x1
- rtb=x1
- ELSE
- dx=x1-x2
- rtb=x2
- END IF
- DO 20 j=1,100
- dx=dx*0.5
- xmid=rtb+dx
- CALL `FNAME`(xmid,y2)
- fmid=y-y2
- IF (fmid.LE.0) THEN
- rtb=xmid
- ENDIF
- IF (DABS(dx).LT.xacc .OR. fmid.EQ.0) THEN
- x=rtb
- GO TO 30
- ENDIF
- 20 CONTINUE
- END IF
- 10 CONTINUE
- x=0.0
- 30 RETURN
- END
-
- !!FORTRAN!!
- *----------------------------------------------------------*`ERF`
- REAL FUNCTION ERF(x)`ERF`
- *----------------------------------------------------------*`ERF`
- DOUBLE PRECISION x`ERF`
- REAL t,z,ans`ERF`
- z=DABS(x)`ERF`
- t=1.0/(1.0+0.5*z)`ERF`
- ans=(t*EXP(-z*z-1.26551223+t*(1.00002368+t*(0.37409196+`ERF`
- 1t*(0.09678418+t*(-0.18628806+t*(0.27886807+t*(-1.13520398+`ERF`
- 1t*(1.48851587+t*(-0.82215223+t*0.17087277))))))))))`ERF`
- IF (x.GE.0.0) THEN`ERF`
- ERF=1.0-ans`ERF`
- ELSE `ERF`
- ERF=-1.0+ans`ERF`
- END IF`ERF`
- RETURN`ERF`
- END`ERF`
-
- *----------------------------------------------------------*
- SUBROUTINE `FNAME`(x,y)
- *----------------------------------------------------------*
- ***** TableCurve `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`
- *----------------------------------------------------------*
- DOUBLE PRECISION x,y
- DOUBLE PRECISION `FLIST`
- DOUBLE PRECISION n`FDECLN`
- x=`FX`
- n=`FBAL2`
- n=`FAUX`
- x1=`F1`
- x2=`F2`
- x3=`F3`
- x4=`F4`
- y=`EQNCODE`
- y=`FY`
- RETURN
- END
- !!FORTRAN!!
- ~~FORTRAN~~
-
-