home *** CD-ROM | disk | FTP | other *** search
Text File | 1988-06-20 | 115.6 KB | 4,583 lines |
- 18-Jun-88 14:43:04-MDT,122930;000000000000
- Return-Path: <u-lchoqu%sunset@cs.utah.edu>
- Received: from cs.utah.edu by SIMTEL20.ARPA with TCP; Sat, 18 Jun 88 14:40:11 MDT
- Received: by cs.utah.edu (5.54/utah-2.0-cs)
- id AA22566; Sat, 18 Jun 88 14:40:04 MDT
- Received: by sunset.utah.edu (5.54/utah-2.0-leaf)
- id AA24739; Sat, 18 Jun 88 14:39:51 MDT
- Date: Sat, 18 Jun 88 14:39:51 MDT
- From: u-lchoqu%sunset@cs.utah.edu (Lee Choquette)
- Message-Id: <8806182039.AA24739@sunset.utah.edu>
- To: rthum@simtel20.arpa
- Subject: SciHelper.c.shar
-
- #! /bin/sh
- #
- # This is a shell archive. Save this into a file, edit it
- # and delete all lines above this comment. Then give this
- # file to sh by executing the command "sh file". The files
- # will be extracted into the current directory owned by
- # you with default permissions.
- #
- # The files contained herein are:
- #
- # 2 SHInfo
- # 1 DiskContents
- # 12 regcmdloop.c
- # 11 reggauss.c
- # 7 reggraph.c
- # 19 regio.c
- # 21 regmain.c
- # 20 regmanip.c
- # 4 regmenu.c
- # 14 regprim.c
- # 1 regtab.m
- #
- echo 'Extracting SHInfo'
- if test -f SHInfo; then echo 'shar: will not overwrite SHInfo'; else
- sed 's/^X//' << '________This_Is_The_END________' > SHInfo
- XSubject: "Scientist's Helper" program source. File 1 of 7
- X
- XScientist's Helper is a data-analysis and graphing program written
- Xby William Menke of the Oceanography Department of Oregon State
- XUniversity. While it isn't StatView, the source is available.
- XIt's written in Aztec C. Conversion to other formats is encouraged.
- X
- XBesides simple graphing and data reduction, it will do multiple
- Xregressions, filtering, Fourier transforms, and other stuff too;
- Xand operations on the output of those operations.
- X
- XMail to me, or to Dr. Menke, by USENET or USSnail, respectively.
- X
- X***All files have been processed by BinHex 4.0 and PackIt_II.***
- X
- XFiles: *** 1: Description, and odds & ends
- X 2: Include file "all.h"
- X 3: Sources: reg{cmdloop,gauss,graph,io}.c
- X 4: Sources: reg{main,manip,menu,prim}.c
- X 5: Sources: reg{proc,series,spline,table,wnd}.c
- X 6. Scientist's Helper appl. v2.7, 1st Half
- X 7: Scientist's Helper appl. v2.7, 2nd Half
- X
- XNathan C. Myers {tektronix|hplabs!hp-pcd}!orstcs!nathan
- X780 NW 11th St. nathan@oregon-state
- XCorvallis, OR 97330 (503) 753-5110
- X
- ________This_Is_The_END________
- if test `wc -l < SHInfo` -ne 27; then
- echo 'shar: SHInfo was damaged during transit'
- echo ' (should have been 27 bytes)'
- fi
- fi ; : end of overwriting check
- echo 'Extracting DiskContents'
- if test -f DiskContents; then echo 'shar: will not overwrite DiskContents'; else
- sed 's/^X//' << '________This_Is_The_END________' > DiskContents
- XDiskette Contents:
- X
- X
- X
- X1) A series of text files with names of the form reg___.c which are the
- Xsource code of scientists helper. These are written in Manx Aztec C and
- Xshould be compiled with the statement: cc -z3000 reg___.c
- X
- X
- X
- X2) Three include files, that define the toolkit utilities and the special data
- Xstructures used by Scientist's Helper
- X
- X
- X
- X3) An input file for the Resource Compiler (RGEN) called regtab.r
- X
- X
- X
- X4) A shell script, regtab.m, that links and rgen's the object code into a
- Xclickable program.
- X
- X
- X
- X5) A program called SetBundle, that lets you set the bundle bit of a file so
- Xthat its icon will appear in the desktop. This program will only work if
- Xthe Aztec terminal driver is installed in your system.
- X
- X
- X
- X6) Edit, a text editor suitable for examining and editing programs (it's
- Xsimilar to MacWrite, except it doesn't wrap text and processes files of
- Xresource type TEXT (not MACA).
- X
- X
- X
- ________This_Is_The_END________
- if test `wc -l < DiskContents` -ne 36; then
- echo 'shar: DiskContents was damaged during transit'
- echo ' (should have been 36 bytes)'
- fi
- fi ; : end of overwriting check
- echo 'Extracting regcmdloop.c'
- if test -f regcmdloop.c; then echo 'shar: will not overwrite regcmdloop.c'; else
- sed 's/^X//' << '________This_Is_The_END________' > regcmdloop.c
- X#include "all.h"
- X#include "regtabext.h"
- X
- XCmdFromWnd(c, fromCommandWindow)
- Xchar c[];
- Xint fromCommandWindow;
- X{
- X if( c[0]=='>' ) { /* get rid of prompt */
- X c[0]=' ';
- X }
- X RegTabCmd( c, fromCommandWindow );
- X}
- X
- XRegTabCmd( c, fromCommandWindow )
- Xchar c[];
- Xint fromCommandWIndow;
- X{
- X int i, j, k, ii, jj;
- X float x, y;
- X char s[cmdWordLen];
- X
- X strncpy( command.cmdStr, c, cmdWordLen-1 );
- X command.cmdStr[cmdWordLen-1] = '\0'; /*just in case*/
- X if( !SBreak(&command, TRUE) ) {
- X WriteLine("bad command line");
- X ErrMsg(command.cmdStr);
- X }
- X strcpy( cmdWord0, command.cmdWord[0] );
- X
- X /*special code to handle case of pending input*/
- X /*several commands ask for input, including the cursor and input commands*/
- X if( pendingFlag ) {
- X pendingFlag=FALSE;
- X NoPendingInput();
- X if( strlen(pentName)!=0 ) {
- X if( !SetVar(pentName,cmdWord0) ) {
- X ErrMsg("couldnt set input variable");
- X }
- X }
- X }
- X else {
- X
- X if( (strlen(cmdWord0)==0) || (strcmp(cmdWord0,"label")==0) ) {
- X ; /*do nothing*/
- X }
- X else if( strcmp(cmdWord0,"quit")==0 ) {
- X doneFlag = TRUE;
- X }
- X else if( (strcmp(cmdWord0,"p")==0) || (strcmp(cmdWord0,"prompt")==0) ) {
- X for( i=1; i<(numCmdWds-1); i++ ) {
- X if(strlen(command.cmdWord[i])!=0) WritePhrase( command.cmdWord[i] );
- X }
- X WriteLine( command.cmdWord[numCmdWds-1] );
- X }
- X else if ( strcmp(cmdWord0,"beep")==0 ) {
- X SysBeep(5);
- X }
- X else if( strcmp(cmdWord0,"setvar")==0 ) {
- X if( !SetVar( command.cmdWord[1], command.cmdWord[2] ) ) {
- X ErrMsg("couldnt create variable");
- X }
- X }
- X else if( strcmp(cmdWord0,"delete")==0 ) {
- X if( (strcmp(command.cmdWord[1],"v")==0) || (strcmp(command.cmdWord[1],"variable")==0) ){
- X if( !DelVar( command.cmdWord[2] ) ) {
- X ErrMsg("couldnt delete variable");
- X }
- X }
- X else {
- X DelCommand();
- X RedoEditWindow();
- X }
- X }
- X else if( (strcmp(cmdWord0,"t")==0) || (strcmp(cmdWord0,"type")==0) ) {
- X if( (strcmp(command.cmdWord[1],"v")==0) || (strcmp(command.cmdWord[1],"variables")==0) ) {
- X ListVars();
- X }
- X else if( (strcmp(command.cmdWord[1],"c")==0) || (strcmp(command.cmdWord[1],"col")==0) ) {
- X SToI( command.cmdWord[2], &i );
- X if( GoodCol(i)!=0 ) {
- X ErrMsg( noSuchColumn );
- X }
- X WriteLine( table.header.colName[i-1] );
- X for( j=1; j<=table.header.rows; j++ ) {
- X CheckAbortMenu();
- X GetTable( j, i, &x );
- X IToS( j, s );
- X strcat( s, " " );
- X WritePhrase( s );
- X RToS( x, s );
- X WriteLine( s );
- X }
- X }
- X
- X else {
- X ErrMsg( noSuchModifier );
- X }
- X }
- X else if( strcmp(cmdWord0,"allocate")==0 ) {
- X SToI( command.cmdWord[1], &i );
- X SToI( command.cmdWord[2], &j );
- X AllocTable( i, j );
- X RedoEditWindow();
- X }
- X else if( strcmp(cmdWord0,"title")==0 ) {
- X strcpy( table.header.title, command.cmdWord[1] );
- X Header2Vars();
- X }
- X else if( strcmp(cmdWord0,"interpolated")==0 ) {
- X if( (strlen(command.cmdWord[1])==0) || (strcmp(command.cmdWord[1],"true")==0) ) {
- X table.header.interpolated = TRUE;
- X }
- X else if( strcmp(command.cmdWord[1],"false")==0 ) {
- X table.header.interpolated = FALSE;
- X }
- X else {
- X ErrMsg( noSuchModifier );
- X }
- X Header2Vars();
- X CreateCol1();
- X RedoEditWindow();
- X }
- X else if( strcmp(cmdWord0,"rows")==0 ) {
- X SToI( command.cmdWord[1], &i );
- X if( GoodRow(i)==2 ) {
- X ErrMsg( noSuchRow );
- X }
- X else {
- X j = table.header.rows;
- X table.header.rows = i;
- X Header2Vars();
- X if( j<i ) {
- X CreateCol1();
- X }
- X RedoEditWindow();
- X }
- X }
- X else if( strcmp(cmdWord0,"cols")==0 ) {
- X SToI( command.cmdWord[1], &i );
- X if( GoodCol(i)==2 ) {
- X ErrMsg( noSuchCol );
- X }
- X else {
- X table.header.cols = i;
- X Header2Vars();
- X RedoEditWindow();
- X }
- X }
- X else if( strcmp(cmdWord0,"start")==0 ) {
- X SToR( command.cmdWord[1], &x, FALSE );
- X table.header.start = x;
- X Header2Vars();
- X CreateCol1();
- X RedoEditWindow();
- X }
- X else if( strcmp(cmdWord0,"samp")==0 ) {
- X SToR( command.cmdWord[1], &x, FALSE );
- X if( x==0.0 ) {
- X ErrMsg("samp cant be zero");
- X }
- X table.header.samp = x;
- X Header2Vars();
- X CreateCol1();
- X RedoEditWindow();
- X }
- X else if( strcmp(cmdWord0,"colname")==0 ) {
- X SToI( command.cmdWord[1], &i );
- X if( GoodCol(i)!=0 ) {
- X ErrMsg( noSuchCol );
- X }
- X strcpy( s, command.cmdWord[2] );
- X s[10] = '\0'; /*just in case its too long*/
- X strcpy( table.header.colName[i-1], s );
- X RedoEditWindow();
- X }
- X else if( strcmp(cmdWord0,"table")==0 ) {
- X SToI( command.cmdWord[1], &i );
- X SToI( command.cmdWord[2], &j );
- X if( strlen(command.cmdWord[3])==0 ) {
- X GetTable(i, j, &x);
- X RToS( x, s );
- X WriteLine( s );
- X }
- X else {
- X SToR( command.cmdWord[3], &x, TRUE );
- X SetTable( i, j, x, FALSE );
- X RedoEditWindow();
- X }
- X }
- X else if( strcmp(cmdWord0,"set")==0 ) {
- X if( strcmp(command.cmdWord[2],"table")==0 ) {
- X SToI( command.cmdWord[3], &i );
- X SToI( command.cmdWord[4], &j );
- X GetTable(i, j, &x);
- X RToS( x, s );
- X if( !SetVar( command.cmdWord[1],s) ) {
- X ErrMsg("couldnt create variable");
- X }
- X }
- X else if( strcmp(command.cmdWord[2],"colname")==0 ) {
- X SToI( command.cmdWord[3], &i );
- X if( GoodCol(i)!=0 ) {
- X ErrMsg( noSuchColumn );
- X }
- X if( !SetVar(command.cmdWord[1],table.header.colName[i-1]) ) {
- X ErrMsg("couldnt create variable");
- X }
- X }
- X else if( strcmp(command.cmdWord[2],"coefficient")==0 ) {
- X SToI( command.cmdWord[3], &i );
- X if( (i<0) || (i>nCoeffs) ) {
- X ErrMsg( "no such coefficient" );
- X }
- X RToS( coeffs[i], s );
- X if( !SetVar(command.cmdWord[1],s )) {
- X ErrMsg("couldnt create variable");
- X }
- X }
- X else {
- X ErrMsg( noSuchModifier );
- X }
- X }
- X else if ( (strcmp(cmdWord0,"x")==0) || (strcmp(cmdWord0,"execute")==0) ) {
- X if( !mem.active ) { /*calls from console construct new label list*/
- X ListLabels(); /*calls from within procedure cannot change procedure memory*/
- X PendingInput();
- X mem.active = TRUE;
- X }
- X if( !FindLabel(command.cmdWord[1],&i) ) {
- X ErrMsg( "cant find label" );
- X }
- X else if( mem.stackPtr >= (stackLen-1) ) {
- X ErrMsg( "too many levels of procedures" );
- X }
- X mem.stackPtr++;
- X mem.stack[mem.stackPtr] = i;
- X i = SetVar("arg1",command.cmdWord[2] ) && SetVar("arg2",command.cmdWord[3] )
- X && SetVar("arg3",command.cmdWord[4] ) && SetVar("arg4",command.cmdWord[5] );
- X if (!i) {
- X ErrMsg("not enough space for argument variables");
- X }
- X }
- X else if( strcmp(cmdWord0,"goto")==0 ) {
- X if( !mem.active ) {
- X ErrMsg("cant goto from console");
- X }
- X if( !FindLabel(command.cmdWord[1],&i) ) {
- X ErrMsg( "cant find label" );
- X }
- X mem.stack[mem.stackPtr] = i;
- X }
- X else if( strcmp(cmdWord0,"return")==0 ) {
- X ReturnCommand();
- X }
- X else if( strcmp(cmdWord0,"for")==0 ) {
- X ForCommand();
- X }
- X else if( strcmp(cmdWord0,"next")==0 ) {
- X NextCommand();
- X }
- X else if( strcmp(cmdWord0,"if")==0 ) {
- X IfCommand();
- X }
- X else if( (strcmp(cmdWord0,"vm")==0) || (strcmp(cmdWord0,"vmath")==0) ) {
- X VMathCommand();
- X }
- X else if( (strcmp(cmdWord0,"vf")==0) || (strcmp(cmdWord0,"vfunction")==0) ) {
- X VFunctionCommand();
- X }
- X else if( strcmp(cmdWord0,"concat")==0 ) {
- X strcpy(s,command.cmdWord[2]);
- X for( i=3; i<numCmdWds; i++ ) {
- X j=cmdWordLen - strlen(s) - 1;
- X strncat(s,command.cmdWord[i],j);
- X }
- X if( !SetVar(command.cmdWord[1],s) ) {
- X ErrMsg("couldnt create variable");
- X }
- X }
- X else if( strcmp(cmdWord0,"sleep")==0 ) {
- X SToR( command.cmdWord[1], &x, FALSE );
- X i = (int)(x*60.0);
- X Delay( (long)i, (long*)(&x));
- X }
- X else if( strcmp(cmdWord0,"input")==0 ) {
- X WriteLine( command.cmdWord[2] );
- X strcpy( pentName, command.cmdWord[1] );
- X pendingFlag=TRUE;
- X PendingInput();
- X }
- X else if( strcmp(cmdWord0,"cursor")==0 ) {
- X WriteLine( command.cmdWord[1] );
- X pentName[0]='\0';
- X pendingFlag=TRUE;
- X PendingInput();
- X SelectWindow(theWindow[grWindow]);
- X }
- X else if( strcmp(cmdWord0,"xaxis")==0 ) {
- X SToR( command.cmdWord[1], &x, FALSE);
- X SToR( command.cmdWord[2], &y, FALSE);
- X if( x<y ) {
- X graph.xMin=x;
- X graph.xMax=y;
- X }
- X else {
- X ErrMsg("xmin > xmax");
- X }
- X Graph2Vars();
- X }
- X else if( strcmp(cmdWord0,"yaxis")==0 ) {
- X SToR( command.cmdWord[1], &x, FALSE);
- X SToR( command.cmdWord[2], &y, FALSE);
- X if( x<y ) {
- X graph.yMin=x;
- X graph.yMax=y;
- X }
- X else {
- X ErrMsg("ymin > ymax");
- X }
- X Graph2Vars();
- X }
- X else if( strcmp(cmdWord0,"plot")==0 ) {
- X PlotCol();
- X }
- X else if( strcmp(cmdWord0,"clear")==0 ) {
- X ClearGraph();
- X }
- X else if( strcmp(cmdWord0,"axes")==0 ) {
- X PlotAxes();
- X }
- X else if( strcmp(cmdWord0,"insert")==0 ) {
- X InsCommand();
- X RedoEditWindow();
- X }
- X else if( strcmp(cmdWord0,"trend")==0 ) {
- X Trend();
- X RedoEditWindow();
- X }
- X else if( strcmp(cmdWord0,"interpolate")==0 ) {
- X TabInterpolate();
- X RedoEditWindow();
- X }
- X else if( strcmp(cmdWord0,"spline")==0 ) {
- X SplInterpolate();
- X RedoEditWindow();
- X }
- X else if( strcmp(cmdWord0,"sort")==0 ) {
- X SortTable();
- X RedoEditWindow();
- X }
- X else if( strcmp(cmdWord0,"polyfit")==0 ) {
- X polyfit();
- X RedoEditWindow();
- X }
- X else if( strcmp(cmdWord0,"multifit")==0 ) {
- X multifit();
- X RedoEditWindow();
- X }
- X else if( strcmp(cmdWord0,"noise")==0 ) {
- X noise();
- X RedoEditWindow();
- X }
- X
- X else if( strcmp(cmdWord0,"mean")==0 ) {
- X Mean();
- X RedoEditWindow();
- X }
- X else if( strcmp(cmdWord0,"swap")==0 ) {
- X SwapCommand();
- X RedoEditWindow();
- X }
- X else if( strcmp(cmdWord0,"copy")==0 ) {
- X CopyCommand();
- X RedoEditWindow();
- X }
- X else if( strcmp(cmdWord0,"scale")==0 ) {
- X GScan();
- X Graph2Vars();
- X }
- X else if( (strcmp(cmdWord0,"cm")==0) || (strcmp(cmdWord0,"cmath")==0) ) {
- X ColMath();
- X RedoEditWindow();
- X }
- X else if( (strcmp(cmdWord0,"cf")==0) || (strcmp(cmdWord0,"cfunction")==0) ) {
- X ColFunction();
- X RedoEditWindow();
- X }
- X else if( strcmp(cmdWord0,"min")==0 ) {
- X SToI( command.cmdWord[1], &i );
- X ColMin( i, &x );
- X RToS( x, s );
- X WriteLine(s);
- X if( !SetVar("min",s) ) {
- X ErrMsg("couldnt set variable");
- X }
- X }
- X else if( strcmp(cmdWord0,"max")==0 ) {
- X SToI( command.cmdWord[1], &i );
- X ColMax( i, &x );
- X RToS( x, s );
- X WriteLine(s);
- X if( !SetVar("max",s) ) {
- X ErrMsg("couldnt set variable");
- X }
- X }
- X else if( strcmp(cmdWord0,"constant")==0 ) {
- X SToR( command.cmdWord[1], &x, TRUE );
- X SToI( command.cmdWord[2], &j );
- X if( strlen(command.cmdWord[3])==0 ) {
- X ii=1;
- X }
- X else {
- X SToI( command.cmdWord[3], &ii );
- X }
- X if( strlen(command.cmdWord[4])==0 ) {
- X jj=table.header.rows;
- X }
- X else {
- X SToI( command.cmdWord[4], &jj );
- X }
- X for( i=ii; i<=jj; i++ ) {
- X SetTable( i, j, x, FALSE );
- X }
- X RedoEditWindow();
- X }
- X else if( strcmp(cmdWord0,"bandpass")==0 ) {
- X bandpass();
- X RedoEditWindow();
- X }
- X else if( strcmp(cmdWord0,"spectrum")==0 ) {
- X spect();
- X RedoEditWindow();
- X }
- X
- X else if( strcmp(cmdWord0,"integrate")==0 ) {
- X integrate();
- X RedoEditWindow();
- X }
- X else if( (strcmp(cmdWord0,"diff")==0) || (strcmp(cmdWord0,"differentiate")==0) ) {
- X differentiate();
- X RedoEditWindow();
- X }
- X else if( strcmp(cmdWord0,"sum")==0 ) {
- X summation();
- X RedoEditWindow();
- X }
- X else if( strcmp(cmdWord0,"histogram")==0 ) {
- X histogram();
- X RedoEditWindow();
- X }
- X else if( strcmp(cmdWord0,"taper")==0 ) {
- X taper();
- X RedoEditWindow();
- X }
- X else if( (strcmp(cmdWord0,"conv")==0) || (strcmp(cmdWord0,"convolve")==0) ) {
- X convolve();
- X RedoEditWindow();
- X }
- X
- X else {
- X ErrMsg("no such command");
- X }
- X
- X } /*end if not pending*/
- X
- X if( (!mem.active) && (!pendingFlag) ) { /*prompt to command window*/
- X currentWindow = coWindow;
- X whichWindow = theWindow[currentWindow];
- X SelectWindow( whichWindow );
- X SetPort(whichWindow);
- X TEInsert( "> ", 2L, coText );
- X IfOutScroll( coText );
- X }
- X
- X}
- ________This_Is_The_END________
- if test `wc -l < regcmdloop.c` -ne 475; then
- echo 'shar: regcmdloop.c was damaged during transit'
- echo ' (should have been 475 bytes)'
- fi
- fi ; : end of overwriting check
- echo 'Extracting reggauss.c'
- if test -f reggauss.c; then echo 'shar: will not overwrite reggauss.c'; else
- sed 's/^X//' << '________This_Is_The_END________' > reggauss.c
- X#include "all.h"
- X#include "regtabext.h"
- X
- Xmultifit()
- X{
- X int indList[32], nInd, i, j, k, n, inWord, yCol, zCol, anyNaN, nstore, ierror, counts, flag;
- X char c, str[80];
- X float t, x[33], y, z, vec[33], *a;
- X if( (strcmp(command.cmdWord[1],"type")!=0) &&
- X (strcmp(command.cmdWord[1],"keep")!=0) &&
- X (strcmp(command.cmdWord[1],"remove")!=0) &&
- X (strcmp(command.cmdWord[1],"compute")!=0) ) {
- X ErrMsg(badModifier);
- X }
- X /*decode independent column list*/
- X n = strlen( command.cmdWord[2] );
- X command.cmdWord[2][n]=' ';
- X command.cmdWord[2][n+1]='\0';
- X n++;
- X nInd = 0;
- X inWord = FALSE;
- X for( i=0; i<n; i++ ) {
- X c = command.cmdWord[2][i];
- X if( (c=='\t') || (c==',') ) c=' ';
- X if( (!inWord) && (c!=' ') ) {
- X inWord=TRUE;
- X nInd++;
- X if( nInd>32 ) ErrMsg("too many independent columns");
- X j=0;
- X str[0]=c;
- X }
- X else if( inWord && (c==' ') ) {
- X j++;
- X str[j]='\0';
- X SToI( str, &(indList[nInd]) );
- X if( GoodCol(indList[nInd])!=0 ) ErrMsg("bad independent column");
- X inWord=FALSE;
- X }
- X else if( inWord && (c!=' ') ) {
- X j++;
- X str[j]=c;
- X } /*end if*/
- X } /*end for i*/
- X if (nInd<1) ErrMsg("too few independent columns");
- X
- X SToI( command.cmdWord[3], &yCol );
- X if( GoodCol(yCol)!=0 ) ErrMsg("bad dependent column");
- X
- X /*allocate matrix and zero it*/
- X nstore = nInd+1;
- X a = NewPtr( 4L * (long)(nstore*nstore) );
- X if( MemError()!=noErr ) ErrMsg("not enough memory");
- X for( i=0; i<nstore; i++ ) {
- X vec[i]=0.0;
- X for( j=0; j<nstore; j++ ) {
- X *(a+i*nstore+j)=0.0;
- X } /*end for j*/
- X } /*end for i*/
- X
- X counts = 0;
- X for( i=1; i<=table.header.rows; i++ ) {
- X x[0]=1.0;
- X anyNaN = FALSE;
- X for( j=1; j<=nInd; j++ ) {
- X GetTable( i, indList[j], &(x[j]) );
- X if( NaN(&x[j]) ) {
- X anyNaN = TRUE;
- X break;
- X } /*end if*/
- X } /*end for j*/
- X GetTable( i, yCol, &y );
- X if( anyNaN || NaN(&y) ) break;
- X counts++;
- X for( j=0; j<nstore; j++ ) {
- X vec[j] += y*x[j];
- X for( k=0; k<nstore; k++ ) {
- X *(a+j*nstore+k) += x[j]*x[k];
- X } /*end for k*/
- X } /*end for j*/
- X } /*end for i*/
- X
- X gauss(a,vec,nstore,nstore,1.0e-6,&ierror,TRUE); /*solve normal equations*/
- X if( ierror!=0 ) {
- X WriteLine( "Warning! singular matrix detected" );
- X }
- X DisposPtr( a );
- X
- X if (strcmp(command.cmdWord[1],"type")==0) {
- X WriteLine("constant term");
- X RToS( vec[0], str );
- X WriteLine( str );
- X WriteLine("coefficients of the indepencent columns");
- X for( i=1; i<=nInd; i++ ) {
- X IToS( indList[i], str );
- X WritePhrase( str );
- X WritePhrase( " " );
- X RToS( vec[i], str );
- X WriteLine( str );
- X } /*end for i*/
- X } /*end if*/
- X else if( (strcmp(command.cmdWord[1],"keep")==0) ||
- X (strcmp(command.cmdWord[1],"remove")==0) ) {
- X if(strcmp(command.cmdWord[1],"remove")==0) {
- X flag=TRUE;
- X }
- X else {
- X flag=FALSE;
- X }
- X SToI( command.cmdWord[4], &zCol );
- X for( i=1; i<=table.header.rows; i++ ) {
- X z=vec[0];
- X for( j=1; j<=nInd; j++ ) {
- X GetTable( i, indList[j], &t );
- X z+=vec[j]*t;
- X } /*end for j*/
- X if (flag) {
- X GetTable( i, yCol, &y );
- X z = y-z;
- X } /*end if*/
- X SetTable( i, zCol, z, FALSE );
- X } /*end for i*/
- X } /*end if*/
- X
- X /*save coefficients, etc*/
- X nCoeffs=nstore;
- X for( i=0; i<=nstore; i++ ) coeffs[i]=vec[i];
- X IToS( counts, str );
- X if( !SetVar( "counts", str ) ) {
- X ErrMsg("couldnt set variable");
- X }
- X}
- X
- Xnoise()
- X{
- X float a, d, r;
- X double xnse();
- X int xCol, i;
- X SToR( command.cmdWord[1], &a, FALSE );
- X SToR( command.cmdWord[2], &d, FALSE );
- X if( d<=0.0 ) ErrMsg("std dev cant be non-positive");
- X SToI( command.cmdWord[3], &xCol );
- X for( i=1; i<=table.header.rows; i++ ) {
- X r = (float) xnse(a,d);
- X SetTable( i, xCol, r, FALSE );
- X }
- X}
- X
- Xdouble xnse(a,d)
- Xfloat a, d;
- X/* returns a random number in a sequence with mean a and standard deviation d */
- X{
- X double sum, t, ss;
- X int i, n=10;
- X sum = 0.0;
- X t = sqrt( (double) (12.0*d*d/n) )/65536.0;
- X for( i=0; i<n; i++ ) {
- X sum += ran();
- X }
- X return( (sum*t + (double)a) );
- X}
- X
- Xpolyfit()
- X{
- X int order, i, j, k, xCol, yCol, zCol, counts, ierror, flag;
- X float a[7][7], vec[7], xn[14], x, y, z, t;
- X char str[40];
- X
- X SToI( command.cmdWord[1], &order );
- X if( (order<1) || (order>6) ) {
- X ErrMsg("order must be in range 1-6");
- X }
- X if( (strcmp(command.cmdWord[2],"type")!=0) &&
- X (strcmp(command.cmdWord[2],"keep")!=0) &&
- X (strcmp(command.cmdWord[2],"remove")!=0) &&
- X (strcmp(command.cmdWord[2],"compute")!=0) ) {
- X ErrMsg(badModifier);
- X }
- X SToI( command.cmdWord[3], &xCol );
- X SToI( command.cmdWord[4], &yCol );
- X if( (GoodCol(xCol)!=0) || (GoodCol(yCol)!=0) ) {
- X ErrMsg( "bad input column");
- X }
- X
- X for( j=0; j<=order; j++ ) { /*zero matrix and vector*/
- X vec[j] = 0.0;
- X for( k=0; k<=order; k++ ) {
- X a[j][k] = 0.0;
- X } /*end for k*/
- X } /*end for k*/
- X
- X counts=0;
- X i=1;
- X while( NextNotNaN( i, xCol, yCol, &i ) ) {
- X counts++;
- X GetTable( i, xCol, &x );
- X GetTable( i, yCol, &y );
- X xn[0]=1.0; /*compute powers of x*/
- X for( j=1; j<=(2*order); j++ ) {
- X xn[j] = x * xn[j-1];
- X } /*end for j*/
- X for( j=0; j<=order; j++ ) { /*zero matrix and vector*/
- X vec[j] += y*xn[j];
- X for( k=0; k<=order; k++ ) {
- X a[j][k] += xn[k+j];
- X } /*end for k*/
- X } /*end for k*/
- X i++;
- X } /*end while*/
- X
- X gauss(a,vec,(order+1),7,1.0e-6,&ierror,TRUE); /*solve normal equations*/
- X if( ierror!=0 ) {
- X WriteLine( "Warning! singular matrix detected" );
- X }
- X
- X if (strcmp(command.cmdWord[2],"type")==0) {
- X WriteLine("coefficients of x to the n, starting with n=0");
- X for( i=0; i<=order; i++ ) {
- X RToS( vec[i], str );
- X WriteLine( str );
- X } /*end for i*/
- X } /*end if*/
- X else if( (strcmp(command.cmdWord[2],"keep")==0) ||
- X (strcmp(command.cmdWord[2],"remove")==0) ) {
- X if(strcmp(command.cmdWord[2],"remove")==0) {
- X flag=TRUE;
- X }
- X else {
- X flag=FALSE;
- X }
- X SToI( command.cmdWord[5], &zCol );
- X for( i=1; i<=table.header.rows; i++ ) {
- X GetTable( i, xCol, &x );
- X xn[0]=1.0;
- X z=vec[0];
- X for( j=1; j<=order; j++ ) {
- X xn[j]=x*xn[j-1];
- X z+=xn[j]*vec[j];
- X } /*end for j*/
- X if (flag) {
- X GetTable( i, yCol, &y );
- X z = y-z;
- X } /*end if*/
- X SetTable( i, zCol, z, FALSE );
- X } /*end for i*/
- X } /*end if*/
- X
- X /*save coefficients, etc*/
- X nCoeffs=order;
- X for( i=0; i<=order; i++ ) coeffs[i]=vec[i];
- X IToS( counts, str );
- X if( !SetVar( "counts", str ) ) {
- X ErrMsg("couldnt set variable");
- X }
- X
- X}
- X
- Xgauss(a,vec,n,nstore,test,ierror,itriag)
- Xfloat *a, vec[], test;
- Xint n, nstore, *ierror, itriag;
- X{
- X
- X/*subroutine gauss, by william menke, july 1978 (modified feb 1983, nov 85) */
- X
- X/* a subroutine to solve a system of n linear equations in n unknowns, where n doesn't exceed 32 */
- X/*gaussian reduction with partial pivoting is used */
- X/* a (sent, destroyed) n by n matrix */
- X/* vec (sent, overwritten) n vector, replaced with solution */
- X/* nstore (sent) dimension of a */
- X/* test (sent) small pos no for div by zero check */
- X/* ierror (returned) error code. zero on no error */
- X/* itriag (sent) matrix triangularized only on TRUE */
- X/* useful when solving multiple */
- X/* systems with same a */
- X static int isub[32], l1;
- X int line[32], iet, ieb, i, j, k, l, j2;
- X float big, testa, b, sum;
- X
- X
- X iet=0; /* initial error flags, one for triagularization*/
- X ieb=0; /* one for backsolving */
- X
- X/* triangularize the matrix a, replacing the zero elements of the triangularized matrix */
- X/* with the coefficients needed to transform the vector vec */
- X
- X if (itriag) { /* triangularize matrix */
- X
- X for( j=0; j<n; j++ ) { /*line is an array of flags*/
- X line[j]=0; /* elements of a are not moved during pivoting. line=0 flags unused lines */
- X } /*end for j*/
- X
- X for( j=0; j<n-1; j++ ) { /* triangularize matrix by partial pivoting */
- X
- X big = 0.0; /* find biggest element in j-th column of unused portion of matrix*/
- X for( l1=0; l1<n; l1++ ) {
- X if( line[l1]==0 ) {
- X testa=(float) fabs( (double) (*(a+l1*nstore+j)) );
- X if (testa>big) {
- X i=l1;
- X big=testa;
- X } /*end if*/
- X } /*end if*/
- X } /*end for l1*/
- X if( big<=test) { /* test for div by 0 */
- X iet=1;
- X } /*end if*/
- X
- X line[i]=1; /* selected unused line becomes used line */
- X isub[j]=i; /* isub points to j-th row of triang. matrix */
- X
- X sum=1.0/(*(a+i*nstore+j)); /* reduce matrix towards triangle */
- X for( k=0; k<n; k++ ) {
- X if( line[k]==0 ) {
- X b=(*(a+k*nstore+j))*sum;
- X for( l=j+1; l<n; l++ ) {
- X *(a+k*nstore+l)=(*(a+k*nstore+l))-b*(*(a+i*nstore+l));
- X } /*end for l*/
- X *(a+k*nstore+j)=b;
- X } /*end if*/
- X } /*end for k*/
- X
- X } /*end for j*/
- X
- X for( j=0; j<n; j++ ) { /*find last unused row and set its pointer*/
- X /* this row contians the apex of the triangle*/
- X if( line[j]==0) {
- X l1=j; /*apex of triangle*/
- X isub[n-1]=j;
- X break;
- X } /*end if*/
- X } /*end for j*/
- X
- X } /*end if itriag true*/
- X
- X /*start backsolving*/
- X
- X for( i=0; i<n; i++ ) { /* invert pointers. line(i) now gives row no in triang matrix */
- X /* of i-th row of actual matrix */
- X line[isub[i]] = i;
- X } /*end for i*/
- X
- X for( j=0; j<n-1; j++) { /* transform the vector to match triang. matrix*/
- X b=vec[isub[j]];
- X for( k=0; k<n; k++ ) {
- X if (line[k]>j) { /* skip elements outside of triangle*/
- X vec[k]=vec[k]-(*(a+k*nstore+j))*b;
- X } /*end if*/
- X } /*end for k*/
- X } /*end for j*/
- X
- X b = *(a+l1*nstore+(n-1)); /*apex of triangle*/
- X if( ((float)fabs( (double) b))<=test) { /*check for div by zero in backsolving*/
- X ieb=2;
- X } /*end if*/
- X vec[isub[n-1]]=vec[isub[n-1]]/b;
- X
- X for( j=n-2; j>=0; j-- ) { /* backsolve rest of triangle*/
- X sum=vec[isub[j]];
- X for( j2=j+1; j2<n; j2++ ) {
- X sum = sum - vec[isub[j2]] * (*(a+isub[j]*nstore+j2));
- X } /*end for j2*/
- X b = *(a+isub[j]*nstore+j);
- X if( ((float)fabs((double)b))<=test) { /* test for div by 0 in backsolving */
- X ieb=2;
- X } /*end if*/
- X vec[isub[j]]=sum/b; /*solution returned in vec*/
- X } /*end for j*/
- X
- X/*put the solution vector into the proper order*/
- X
- X for( i=0; i<n; i++ ) { /* reorder solution */
- X for( k=i; k<n; k++ ) { /* search for i-th solution element */
- X if( line[k]==i ) {
- X j=k;
- X break;
- X } /*end if*/
- X } /*end for k*/
- X b = vec[j]; /* swap solution and pointer elements*/
- X vec[j] = vec[i];
- X vec[i] = b;
- X line[j] = line[i];
- X } /*end for i*/
- X
- X *ierror = iet + ieb; /* set final error flag*/
- ________This_Is_The_END________
- if test `wc -l < reggauss.c` -ne 383; then
- echo 'shar: reggauss.c was damaged during transit'
- echo ' (should have been 383 bytes)'
- fi
- fi ; : end of overwriting check
- echo 'Extracting reggraph.c'
- if test -f reggraph.c; then echo 'shar: will not overwrite reggraph.c'; else
- sed 's/^X//' << '________This_Is_The_END________' > reggraph.c
- X#include "all.h"
- X#include "regtabext.h"
- X
- XNextNotNan(startRow, x, y, foundRow)
- Xint startRow, x, y, *foundRow;
- X/*searches through two columns of table, and returns first row after*/
- X/*and including startRow that has no Nans in the columns*/
- X{
- X int i, bothNaN;
- X float fx, fy;
- X
- X *foundRow = 0;
- X bothNaN=TRUE;
- X for (i=startRow; ((i<=table.header.rows) && bothNaN); i++ ) {
- X GetTable( i, x, &fx );
- X GetTable( i, y, &fy );
- X if( (!NaN(&fx)) && (!NaN(&fy)) ) {
- X *foundRow = i;
- X bothNaN = FALSE;
- X } /* end if */
- X } /*end for*/
- X return(!bothNaN);
- X}
- X
- XGraphScale( x, y, ix, iy ) /*to pixel coordinates*/
- Xfloat x, y;
- Xint *ix, *iy;
- X{
- X float xs, ys;
- X xs = ((float)(grXMax-grXMin))*(x-graph.xMin)/(graph.xMax-graph.xMin);
- X ys = ((float)(grYMin-grYMax))*(y-graph.yMin)/(graph.yMax-graph.yMin);
- X xs = xs + (float)grXMin;
- X ys = (float)grYMin-ys;
- X
- X if( (xs>=(-32760.0)) && (xs<=32760.0) ) {
- X *ix=(int)xs;
- X }
- X else if( xs<(-32760.0) ) {
- X *ix = -32760;
- X }
- X else {
- X *ix = 32760;
- X }
- X
- X if( (ys>=(-32760.0)) && (ys<32760.0) ) {
- X *iy=(int)ys;
- X }
- X else if( ys<(-32760) ) {
- X *iy = -32760;
- X }
- X else {
- X *iy = 32760;
- X }
- X}
- X
- XInvGraphScale( ix, iy, x, y) /*pixels to graph coordinates*/
- Xint ix, iy;
- Xfloat *x, *y;
- X{
- X ix = ix-grXMin;
- X iy = grYMin-iy;
- X *x =( ( (float)(ix) / ((float)(grXMax-grXMin)) ) * (graph.xMax-graph.xMin) ) + graph.xMin;
- X *y =( ( (float)(iy) / ((float)(grYMin-grYMax)) ) * (graph.yMax-graph.yMin) ) + graph.yMin;
- X}
- X
- XPlotCol()
- X{
- X int xcol, ycol, firstRow, nextRow, i, j, oldWindow, width;
- X int startRow, endRow, dx, dy, continuous, pat, refresh;
- X float x1, y1;
- X char symbol, s[cmdWordLen];
- X GrafPtr oldPort;
- X
- X SToI( command.cmdWord[1], &xcol );
- X SToI( command.cmdWord[2], &ycol );
- X if (GoodCol(xcol)!=0) {
- X ErrMsg("bad x col");
- X }
- X if (GoodCol(ycol)!=0) {
- X ErrMsg("bad y col");
- X }
- X
- X if( table.header.rows >= 1000 ) {
- X refresh = 100;
- X }
- X else {
- X refresh = 10;
- X }
- X
- X strcpy( s, command.cmdWord[3] );
- X pat=0;
- X width=1;
- X if( (strlen(s)==0) || (strcmp(s,"solid")==0) ){
- X continuous =TRUE;
- X pat=0; /*black*/
- X width=1;
- X }
- X else if (strcmp(s,"dashed")==0) {
- X continuous =TRUE;
- X width=2;
- X pat=1; /*gray*/
- X }
- X else if (strcmp(s,"dotted")==0) {
- X continuous = TRUE;
- X pat=2; /*ltGray*/;
- X width=2;
- X }
- X else if (strcmp(s,"bold")==0) {
- X continuous = TRUE;
- X pat=0; /*black*/
- X width=2;
- X }
- X else if (strcmp(s,"dots")==0) {
- X continuous =FALSE;
- X dx=2;
- X dy =1;
- X symbol='.';
- X }
- X else if (strcmp(s,"crosses")==0) {
- X continuous=FALSE;
- X symbol = '+';
- X dx=2;
- X dy=5;
- X }
- X else if (strcmp(s,"circles")==0) {
- X continuous = FALSE;
- X symbol = 'o';
- X dx = 3;
- X dy = 3;
- X }
- X else if (strcmp(s,"stars")==0) {
- X continuous = FALSE;
- X symbol = '*';
- X dx = 2;
- X dy = 5;
- X }
- X else if (strcmp(s,"x")==0) {
- X continuous = FALSE;
- X symbol = 'x';
- X dx = 2;
- X dy = 3;
- X }
- X else {
- X ErrMsg("bad plotting symbol");
- X }
- X
- X GetPort( &oldPort );
- X oldWindow=currentWindow;
- X
- X SetPort(grPortPtr);
- X TextFont(monaco);
- X TextSize(9);
- X
- X if( pat==1 ) {
- X PenPat( gray );
- X }
- X else if( pat==2 ) {
- X PenPat( ltGray );
- X }
- X else {
- X PenPat( black );
- X }
- X PenSize( width, width );
- X
- X /*determine limits: dont plot interpolated data outside box*/
- X if( (table.header.interpolated) && (xcol==1) ) {
- X x1=1.0 + (graph.xMin-table.header.start)/table.header.samp;
- X if ((x1-1.0)<1.0) {
- X startRow =1;
- X }
- X else if ((x1-1.0)>((float)table.header.rows)) {
- X startRow = table.header.rows;
- X }
- X else {
- X startRow = (int)(x1-1.0);
- X }
- X x1 = 1.0 + (graph.xMax-table.header.start)/table.header.samp;
- X if( (x1+1.0)<1.0 ) {
- X endRow=1;
- X }
- X else if( (x1+1.0)>((float)table.header.rows) ) {
- X endRow=table.header.rows;
- X }
- X else {
- X endRow = (int)(x1+1.0);
- X }
- X }
- X else {
- X startRow =1;
- X endRow = table.header.rows;
- X }
- X
- X if( NextNotNan(startRow,xcol,ycol, &firstRow) ) {
- X GetTable( firstRow, xcol, &x1 );
- X GetTable( firstRow, ycol, &y1 );
- X GraphScale( x1, y1, &i, &j );
- X if (continuous) {
- X MoveTo( i, j );
- X }
- X else {
- X MoveTo( i-dx, j+dy );
- X DrawText(&symbol, 0, 1);
- X }
- X firstRow++;
- X while( (firstRow<=endRow) && NextNotNan(firstRow,xcol,ycol,&nextRow) ) {
- X GetTable( nextRow, xcol, &x1 );
- X GetTable( nextRow, ycol, &y1 );
- X GraphScale( x1, y1, &i, &j );
- X if (continuous) {
- X LineTo( i, j );
- X }
- X else {
- X MoveTo( i-dx, j+dy );
- X DrawText(&symbol,0,1);
- X }
- X firstRow=nextRow + 1;
- X if( (nextRow%refresh)==0) {
- X CheckAbortMenu();
- X currentWindow=grWindow;
- X whichWindow=theWindow[grWindow];
- X SetPort( whichWindow );
- X DrawWindow();
- X SetPort( grPortPtr );
- X }
- X } /*end while*/
- X } /*end if*/
- X
- X SetPort( theWindow[grWindow] );
- X InvalRect( &(theWindow[grWindow]->portRect) );
- X
- X SetPort( oldPort );
- X currentWindow=oldWindow;
- X whichWindow=theWindow[currentWindow];
- X}
- X
- XClearGraph()
- X{
- X int oldWindow;
- X GrafPtr oldPort;
- X
- X GetPort( &oldPort );
- X oldWindow=currentWindow;
- X
- X SetPort( grPortPtr );
- X EraseRect( &(grPort.portRect) );
- X FrameRect(&(grPort.portRect) );
- X
- X SetPort( theWindow[grWindow] );
- X InvalRect( &(theWindow[grWindow]->portRect) );
- X
- X SetPort( oldPort );
- X currentWindow=oldWindow;
- X whichWindow=theWindow[currentWindow];
- X}
- X
- XPlotAxes()
- X{
- X int i, ii, j, k, width, slen;
- X float x, interval;
- X char s[cmdWordLen];
- X int oldWindow;
- X GrafPtr oldPort;
- X Rect tRect;
- X
- X GetPort( &oldPort );
- X oldWindow=currentWindow;
- X
- X SetPort( grPortPtr );
- X PenPat( black );
- X PenSize(1,1);
- X TextFont(monaco);
- X TextSize(9);
- X
- X SetRect( &tRect, 1, 1, (grXMin-1), (windowHeight-1) );
- X EraseRect(&tRect);
- X
- X SetRect( &tRect, 1, (grYMin+1), (windowWidth-1), (windowHeight-1) );
- X EraseRect(&tRect);
- X
- X MoveTo( grXMin, grYMin ); /*x axis*/
- X LineTo( grXMax, grYMin );
- X
- X MoveTo( grXMin, grYMin); /*y axis*/
- X LineTo( grXMin, grYMax);
- X
- X interval = (graph.yMax-graph.yMin)/5.0;
- X for( i=0; i<=5; i++ ) {
- X x=graph.yMin + (float)(i)*interval;
- X GraphScale(graph.xMin,x,&k,&j);
- X MoveTo( grXMin, j );
- X LineTo( (grXMin+6), j );
- X RToS( x, s );
- X MoveTo( 5, (j+4) );
- X DrawText( s, 0, strlen(s) );
- X }
- X
- X interval = (graph.xMax-graph.xMin)/5.0;
- X for (i=0; i<=5; i++ ) {
- X x=graph.xMin + (float)(i)*interval;
- X GraphScale(x,graph.yMin,&j,&k);
- X MoveTo( j, grYMin);
- X LineTo( j, (grYMin-6) );
- X RToS( x, s );
- X width=0;
- X slen=strlen(s);
- X for( ii=0; ii<slen; ii++) {
- X width+=CharWidth(s[ii]);
- X }
- X MoveTo( (j-(width/2)), (grYMin+15) );
- X DrawText( s, 0, slen );
- X }
- X
- X SetPort( theWindow[grWindow] );
- X InvalRect( &(theWindow[grWindow]->portRect) );
- X
- X SetPort( oldPort );
- X currentWindow=oldWindow;
- X whichWindow=theWindow[currentWindow];
- ________This_Is_The_END________
- if test `wc -l < reggraph.c` -ne 318; then
- echo 'shar: reggraph.c was damaged during transit'
- echo ' (should have been 318 bytes)'
- fi
- fi ; : end of overwriting check
- echo 'Extracting regio.c'
- if test -f regio.c; then echo 'shar: will not overwrite regio.c'; else
- sed 's/^X//' << '________This_Is_The_END________' > regio.c
- X#include "all.h"
- X#include "regtabext.h"
- X
- XWriteGraph(reply)
- XSFReply *reply;
- X{
- X int f, i, j, k, vsize, hsize;
- X char str[256];
- X long count, bytesAvailable, pntg, mpnt, dstBytes;
- X Finfo info;
- X char dstbuf[512], srcbuf[512];
- X char *srcPtr, *dstPtr, *mypointer;
- X
- X if( !(reply->good) ) {
- X return;
- X }
- X
- X strncpy( &pntg, "PNTG", 4 );
- X strncpy( &mpnt, "MPNT", 4 );
- X
- X if( GetFInfo( reply->fName, reply->vRefNum, &info )==noErr ) { /*delete old file, if any*/
- X if( info.fdType!=pntg ) {
- X ErrMsg("cant overwrite a non-Paint file");
- X }
- X else {
- X if( FSDelete(reply->fName, reply->vRefNum)!=noErr ) {
- X ErrMsg("couldnt delete existing file");
- X }
- X }
- X }
- X
- X bytesAvailable = 0;
- X for( i=0; i<10; i++ ) {
- X k=GetVInfo( i, str, &j, &count );
- X if( (k==noErr) && (j==reply->vRefNum) ) {
- X bytesAvailable=count;
- X break;
- X }
- X }
- X
- X /* I really should check here if there is enough space on disk */
- X /* but I dont really see how to do this without compressing the entire bit map first*/
- X
- X if( Create(reply->fName, reply->vRefNum, mpnt, pntg)!=noErr ) {
- X ErrMsg("couldnt create file");
- X }
- X
- X if( FSOpen(reply->fName, reply->vRefNum, &f )!=noErr ) {
- X ErrMsg("couldnt open file");
- X }
- X
- X if( SetFPos( f, fsFromStart, 0L )!=noErr ) {
- X ErrMsg("couldnt find beginning of file");
- X }
- X
- X for( i=0; i<512; i++ ) { /*header is block of 512 nulls*/
- X dstbuf[i]=0;
- X }
- X count=512L;
- X k = FSWrite(f, &count, &dstbuf[0] );
- X if( (k!=noErr) || (count!=512L) ){
- X FSClose(f);
- X ErrMsg("couldnt write graph");
- X }
- X
- X mypointer = grMap.baseAddr;
- X hsize = grMap.rowBytes;
- X vsize = grMap.bounds.bottom - grMap.bounds.top;
- X
- X for( j=1; j<=720; j++ ) {
- X srcPtr = &srcbuf[0];
- X dstPtr = &dstbuf[0];
- X for( i=0; i<72; i++ ) {
- X if( (i<hsize) && (j<=vsize) ) {
- X srcbuf[i]=*mypointer;
- X mypointer++;
- X }
- X else {
- X srcbuf[i] = 0;
- X }
- X }
- X PackBits( &srcPtr, &dstPtr,72);
- X dstBytes = (long)(dstPtr-&dstbuf[0]);
- X count = dstBytes;
- X k = FSWrite(f, &count, &dstbuf[0] );
- X if( (k!=noErr) || (count!=dstBytes) ){
- X FSClose(f);
- X ErrMsg("couldnt write graph");
- X }
- X } /*end for*/
- X
- X if( FSClose(f)!=noErr ) {
- X ErrMsg("couldnt close file");
- X }
- X
- X FlushVol( str, reply->vRefNum );
- X}
- X
- XReadProcedure(reply)
- XSFReply *reply;
- X{
- X char str[512];
- X int i, j, k, f, oldWindow;
- X long regTabType, count;
- X Finfo info;
- X GrafPtr oldPort;
- X
- X if( !(reply->good) ) {
- X return;
- X }
- X
- X strncpy( (char*)(®TabType), "TEXT", 4 );
- X
- X if( GetFInfo( reply->fName, reply->vRefNum, &info )!=noErr ) {
- X ErrMsg("couldnt get file info");
- X }
- X if( info.fdType!=regTabType ) {
- X ErrMsg("not a Text file");
- X }
- X
- X /*open file*/
- X
- X if( FSOpen( reply->fName, reply->vRefNum, &f)!=noErr ) {
- X ErrMsg("couldnt open file");
- X }
- X SetFPos( f, fsFromStart, 0L );
- X
- X GetPort(&oldPort);
- X oldWindow=currentWindow;
- X
- X currentWindow=prWindow;
- X whichWindow=theWindow[prWindow];
- X SetPort(whichWindow);
- X
- X TESetSelect( (long)((*prText)->teLength),(long)((*prText)->teLength),prText);
- X TEKey( '\r', prText );
- X TEKey( '\r', prText );
- X
- X for( i=0; i<63; i++ ) {
- X count=512L;
- X k=FSRead(f,&count,str);
- X if( (k==noErr) || (k==eofErr) ) {
- X TEInsert( str, count, prText );
- X }
- X else {
- X break;
- X }
- X if( count<512L ) {
- X break;
- X }
- X } /*end for*/
- X FSClose(f);
- X IfOutScroll(prText);
- X
- X SetPort( oldPort );
- X currentWindow=oldWindow;
- X whichWindow=theWindow[currentWindow];
- X}
- X
- X
- XWriteProcedure(reply)
- XSFReply *reply;
- X{
- X int f, i, j, k;
- X char str[256];
- X long count, bytesNeeded, bytesAvailable, regTabType;
- X Finfo info;
- X
- X if( !(reply->good) ) {
- X return;
- X }
- X
- X strncpy( ®TabType, "TEXT", 4 );
- X
- X if( GetFInfo( reply->fName, reply->vRefNum, &info )==noErr ) { /*delete old file, if any*/
- X if( info.fdType!=regTabType ) {
- X ErrMsg("cant overwrite a non-Text file");
- X }
- X else {
- X if( FSDelete(reply->fName, reply->vRefNum)!=noErr ) {
- X ErrMsg("couldnt delete existing file");
- X }
- X }
- X }
- X
- X bytesNeeded = (*prText)->teLength;
- X bytesAvailable = 0;
- X for( i=0; i<10; i++ ) {
- X k=GetVInfo( i, str, &j, &count );
- X if( (k==noErr) && (j==reply->vRefNum) ) {
- X bytesAvailable=count;
- X break;
- X }
- X }
- X if( bytesAvailable<bytesNeeded ) {
- X ErrMsg( "not enough space on disk" );
- X }
- X
- X if( Create(reply->fName, reply->vRefNum, regTabType, regTabType)!=noErr ) {
- X ErrMsg("couldnt create file");
- X }
- X
- X if( FSOpen(reply->fName, reply->vRefNum, &f )!=noErr ) {
- X ErrMsg("couldnt open file");
- X }
- X
- X if( SetFPos( f, fsFromStart, 0L )!=noErr ) {
- X ErrMsg("couldnt find beginning of file");
- X }
- X
- X count=bytesNeeded;
- X HLock( (*prText)->hText );
- X k = FSWrite(f, &count, *((*prText)->hText) );
- X HUnlock( (*prText)->hText );
- X
- X if( (k!=noErr) || (count!=bytesNeeded) ){
- X FSClose(f);
- X ErrMsg("couldnt write procedure");
- X }
- X
- X if( FSClose(f)!=noErr ) {
- X ErrMsg("couldnt close file");
- X }
- X
- X FlushVol( str, reply->vRefNum );
- X}
- X
- XReadAsciiTable(reply)
- XSFReply *reply;
- X{
- X char cLast, str[512], s[80];
- X int i, j, k, f, lines, columns, firstReturn;
- X long regTabType, count;
- X Finfo info;
- X float x;
- X GrafPtr oldPort;
- X
- X if( !(reply->good) ) {
- X return;
- X }
- X
- X GetPort(&oldPort);
- X SetPort( theWindow[edWindow] );
- X InvalRect( &(theWindow[edWindow]->portRect) );
- X SetPort( oldPort );
- X
- X strncpy( (char*)(®TabType), "TEXT", 4 );
- X
- X if( GetFInfo( reply->fName, reply->vRefNum, &info )!=noErr ) {
- X ErrMsg("couldnt get file info");
- X }
- X if( info.fdType!=regTabType ) {
- X ErrMsg("not a Text file");
- X }
- X
- X /*open file*/
- X
- X if( FSOpen( reply->fName, reply->vRefNum, &f)!=noErr ) {
- X ErrMsg("couldnt open file");
- X }
- X SetFPos( f, fsFromStart, 0L );
- X
- X /* determine size of table*/
- X lines = 0;
- X columns = 0;
- X i=0; /*counts tabs per line*/
- X j=0; /*counts characters*/
- X cLast='\0';
- X firstReturn=TRUE;
- X while( lines<=4097 ) { /*loop over lines in file */
- X count=1L;
- X k=FSRead(f,&count,str);
- X if( (count!=1L) || (k!=noErr) ) {
- X if( (cLast=='\r') || (!firstReturn) ) {
- X break;
- X }
- X else {
- X str[0]='\r';
- X firstReturn=FALSE;
- X }
- X }
- X j++;
- X cLast=str[0];
- X if( str[0]=='\t') {
- X i++;
- X }
- X else if( str[0]=='\r' ) {
- X lines++;
- X if( i>columns ) {
- X columns=i;
- X }
- X i=0;
- X } /*end if*/
- X } /*end while*/
- X columns++; /*since tabs were counted*/
- X if( columns>32 ) {
- X columns=32;
- X }
- X lines--; /*since first line is colnames*/
- X FSClose(f);
- X
- X /* set up table header */
- X if( (lines>table.header.rows) || (columns>table.header.cols) ) {
- X AllocTable( lines, columns );
- X WriteLine("Warning: table allocation changed");
- X }
- X else {
- X table.header.rows = lines;
- X table.header.cols = columns;
- X }
- X table.header.interpolated = FALSE;
- X for( i=1; i<=table.header.cols; i++ ) {
- X strcpy( s, "Col " );
- X IToS( i, &(s[4]) );
- X strcpy( table.header.colName[i-1], s );
- X } /*end for*/
- X for( i=1; i<=table.header.rows; i++ ) {
- X for( j=1; j<=table.header.cols; j++ ) {
- X SetTable(i,j,infinity,FALSE);
- X }} /*end fors*/
- X
- X /* now read in the data */
- X if( FSOpen( reply->fName, reply->vRefNum, &f)!=noErr ) {
- X ErrMsg("couldnt open file");
- X }
- X SetFPos( f, fsFromStart, 0L );
- X
- X /*read colnames*/
- X i=1;
- X s[0]='\0';
- X while( i<=table.header.cols ) {
- X count=1L;
- X k=FSRead(f,&count,str);
- X if( (count!=1L) || (k!=noErr) ) {
- X break;
- X }
- X str[1]='\0';
- X if( (str[0]=='\t') || (str[0]=='\r') ) {
- X strcpy( table.header.colName[i-1], s );
- X i++;
- X s[0]='\0';
- X if( str[0]=='\r' ) {
- X break;
- X }
- X }
- X else {
- X strcat( s, str );
- X }
- X } /*end while*/
- X
- X /*read table entries*/
- X i=1;
- X s[0]='\0';
- X cLast='\0';
- X firstReturn=TRUE;
- X while( i<=table.header.rows ) {
- X j=1;
- X while( j<=table.header.cols ) {
- X count=1L;
- X k=FSRead(f,&count,str);
- X if( (count!=1L) || (k!=noErr) ) {
- X if( (cLast=='\r') || (!firstReturn) ) {
- X break;
- X }
- X else {
- X str[0]='\r';
- X firstReturn=FALSE;
- X }
- X }
- X str[1]='\0';
- X cLast=str[0];
- X if( (str[0]=='\t') || (str[0]=='\r') ) {
- X SToR( s, &x, TRUE );
- X SetTable(i,j,x,TRUE);
- X j++;
- X s[0]='\0';
- X if( str[0]=='\r' ) {
- X i++;
- X break;
- X }
- X }
- X else {
- X strcat( s, str );
- X }
- X } /*end while j*/
- X } /*end while i*/
- X FSClose(f);
- X Header2Vars();
- X}
- X
- XWriteAsciiTable(reply)
- XSFReply *reply;
- X{
- X int f, i, j, k;
- X char str[256];
- X long count, bytesNeeded, regTabType;
- X Finfo info;
- X float x;
- X
- X if( !(reply->good) ) {
- X return;
- X }
- X
- X strncpy( ®TabType, "TEXT", 4 );
- X
- X if( GetFInfo( reply->fName, reply->vRefNum, &info )==noErr ) { /*delete old file, if any*/
- X if( info.fdType!=regTabType ) {
- X ErrMsg("cant overwrite a non-Text file");
- X }
- X else {
- X if( FSDelete(reply->fName, reply->vRefNum)!=noErr ) {
- X ErrMsg("couldnt delete existing file");
- X }
- X }
- X }
- X
- X if( Create(reply->fName, reply->vRefNum, regTabType, regTabType)!=noErr ) {
- X ErrMsg("couldnt create file");
- X }
- X
- X if( FSOpen(reply->fName, reply->vRefNum, &f )!=noErr ) {
- X ErrMsg("couldnt open file");
- X }
- X
- X if( SetFPos( f, fsFromStart, 0L )!=noErr ) {
- X ErrMsg("couldnt find beginning of file");
- X }
- X
- X for( i=1; i<=table.header.cols; i++ ) {
- X strcpy( str, table.header.colName[i-1] );
- X if( i<table.header.cols ) {
- X strcat( str, "\t" );
- X }
- X else {
- X strcat( str, "\r" );
- X }
- X bytesNeeded = (long) strlen( str );
- X count=bytesNeeded;
- X k = FSWrite(f, &count, str );
- X if( (k!=noErr) || (count!=bytesNeeded) ){
- X FSClose(f);
- X ErrMsg("couldnt write colnames");
- X }
- X } /*end for*/
- X
- X for( i=1; i<=table.header.rows; i++ ) {
- X for( j=1; j<=table.header.cols; j++ ) {
- X GetTable(i,j,&x);
- X RToS( x, str );
- X if( j<table.header.cols ) {
- X strcat( str, "\t" );
- X }
- X else {
- X strcat( str, "\r" );
- X }
- X bytesNeeded = (long) strlen( str );
- X count=bytesNeeded;
- X k = FSWrite(f, &count, str );
- X if( (k!=noErr) || (count!=bytesNeeded) ){
- X FSClose(f);
- X ErrMsg("couldnt write table");
- X } /*end if*/
- X } } /*end fors*/
- X
- X if( FSClose(f)!=noErr ) {
- X ErrMsg("couldnt close file");
- X }
- X
- X FlushVol( str, reply->vRefNum );
- X}
- X
- XMean()
- X{
- X int i, colx, coly, stat;
- X float sum, sum2, x, mean, stdDev, n;
- X char str1[cmdWordLen], str2[cmdWordLen];
- X
- X SToI( command.cmdWord[2], &colx );
- X sum = 0.0;
- X sum2 = 0.0;
- X n = 0.0;
- X i = 1;
- X
- X while ( NextNotNan(i,colx,colx,&i) ) {
- X GetTable(i,colx,&x);
- X sum += x;
- X sum2 += x*x;
- X n += 1.0;
- X i++;
- X }
- X
- X mean = sum / n;
- X stdDev = sqrt( (n*sum2 - sum*sum)/(n*(n-1)) );
- X
- X strcpy(str2,"mean ");
- X RToS( mean, str1 );
- X stat = SetVar("mean",str1);
- X strcat( str2, str1 );
- X
- X RToS( stdDev, str1 );
- X stat = stat && SetVar("stddev",str1);
- X strcat(str2, " stddev ");
- X strcat(str2, str1 );
- X
- X RToS( n, str1 );
- X stat = stat && SetVar("counts",str1);
- X strcat( str2, " counts ");
- X strcat( str2, str1 );
- X
- X if( strcmp(command.cmdWord[1],"type")==0 ) {
- X WriteLine(str2);
- X }
- X else if( strcmp(command.cmdWord[1],"keep")==0 ) {
- X SToI( command.cmdWord[3], &coly );
- X for( i=1; i<=table.header.rows; i++ ) {
- X SetTable(i,coly,mean,FALSE);
- X }
- X }
- X else if( strcmp(command.cmdWord[1],"remove")==0 ) {
- X SToI( command.cmdWord[3], &coly );
- X for( i=1; i<=table.header.rows; i++ ) {
- X GetTable(i,colx,&x);
- X SetTable(i,coly,(x-mean),FALSE);
- X }
- X }
- X else if( strcmp(command.cmdWord[1],"compute")==0 ) {
- X ;
- X }
- X else {
- X ErrMsg(badModifier);
- X }
- X
- X if( !stat ) {
- X ErrMsg("couldnt set variables");
- X }
- X}
- X
- X
- XTrend()
- X{
- X int i, colx, coly, colz, stat;
- X float x, y, sumX, sumY, sumX2, sumY2, sumXY, idata;
- X float s0, intercept, slope, errIntercept, errSlope;
- X char str1[cmdWordLen], str2[cmdWordLen];
- X
- X SToI( command.cmdWord[2], &colx );
- X SToI( command.cmdWord[3], &coly );
- X sumX = 0.0;
- X sumY = 0.0;
- X sumX2 = 0.0;
- X sumY2 = 0.0;
- X sumXY = 0.0;
- X idata = 0.0;
- X
- X i = 1;
- X while( NextNotNan(i,colx,coly,&i) ) {
- X GetTable(i,colx,&x);
- X GetTable(i,coly,&y);
- X sumX += x;
- X sumY += y;
- X sumX2 += x*x;
- X sumY2 += y*y;
- X sumXY += x*y;
- X idata += 1.0;
- X i++;
- X }
- X
- X slope = (sumXY - (sumX*sumY/idata)) / (sumX2-(sumX*sumX/idata));
- X intercept = (sumY/idata) - (slope*(sumX/idata));
- X
- X s0 = sumY2 - (sumY*sumY/idata) - (slope*(sumXY - sumX*(sumY/idata)));
- X s0 = s0 / (idata-2.0);
- X errIntercept = sqrt( (double)(s0 * sumX2 / (idata*(sumX2 - (sumX*sumX/idata)))) );
- X errSlope = sqrt( (double) (s0 / (sumX2 - (sumX*sumX/idata))) );
- X
- X RToS(slope,str2);
- X stat = SetVar("slope",str2);
- X strcpy( str1,"slope ");
- X strcat( str1, str2 );
- X
- X RToS( intercept, str2 );
- X stat = stat && SetVar("intercept",str2);
- X strcat( str1, " intercept ");
- X strcat( str1, str2 );
- X
- X RToS( idata, str2 );
- X stat = stat && SetVar("counts", str2);
- X strcat( str1, " counts ");
- X strcat( str1, str2 );
- X
- X if( strcmp(command.cmdWord[1],"type")==0 ) {
- X WriteLine(str1);
- X }
- X
- X RToS(errSlope,str2);
- X stat = stat && SetVar("errslope",str2);
- X strcpy( str1, "errslope ");
- X strcat( str1, str2 );
- X
- X RToS( errIntercept, str2 );
- X stat = stat&& SetVar("errintercept",str2);
- X strcat( str1, " errintercept ");
- X strcat( str1, str2 );
- X
- X if (strcmp(command.cmdWord[1],"type")==0 ) {
- X WriteLine(str1);
- X }
- X else if (strcmp(command.cmdWord[1],"keep")==0 ) {
- X SToI( command.cmdWord[4], &colz );
- X for ( i=1; i<=table.header.rows; i++ ) {
- X GetTable(i,colx,&x);
- X SetTable(i,colz,(intercept+(slope*x)),FALSE);
- X }
- X }
- X else if (strcmp(command.cmdWord[1],"remove")==0 ) {
- X SToI( command.cmdWord[4], &colz );
- X for ( i=1; i<=table.header.rows; i++ ) {
- X GetTable(i,colx,&x);
- X GetTable(i,coly,&y);
- X SetTable(i,colz,y-(intercept+(slope*x)),FALSE);
- X }
- X }
- X else if (strcmp(command.cmdWord[1],"compute")==0 ) {
- X ;
- X }
- X else {
- X ErrMsg(badModifier);
- X }
- X
- X if( !stat ) {
- X ErrMsg("couldnt set variables");
- X }
- X}
- X
- XSortTable()
- X{
- X int sortCol, i, j, k, cmp();
- X sortRec *s;
- X long bytesNeeded;
- X float x;
- X
- X SToI( command.cmdWord[1], &sortCol );
- X if (table.header.interpolated) {
- X ErrMsg("cant sort interpolated table");
- X }
- X if( GoodCol(sortCol)!=0 ) {
- X ErrMsg("column not in table");
- X }
- X bytesNeeded = 6L * (3L + (long)(table.header.rows));
- X if( (s=NewPtr(bytesNeeded)) == 0L ) {
- X ErrMsg("not enough free memory");
- X }
- X for( i=1; i<=table.header.rows; i++ ) {
- X (s+i)->r = i;
- X GetTable( i, sortCol, &x );
- X if( NaN(&x) ) {
- X (s+i)->v = minfinity; /*nan's sorted to bottom of table*/
- X }
- X else {
- X (s+i)->v = x;
- X }
- X } /*end for*/
- X qsort( (s+1), table.header.rows, 6, cmp );
- X for( j=1; j<=table.header.cols; j++ ) {
- X for( i=1; i<=table.header.rows; i++ ) {
- X GetTable( (s+i)->r, j, &x );
- X (s+i)->v = x;
- X }
- X for( i=1; i<=table.header.rows; i++ ) {
- X SetTable( i, j, (s+i)->v, FALSE );
- X }
- X } /* end for j */
- X DisposPtr(s);
- X}
- X
- Xcmp(a,b)
- XsortRec *a, *b;
- X{
- X if( (a->v) < (b->v) ) {
- X return(-1);
- X }
- X else if( (a->v) == (b->v) ) {
- X return(0);
- X }
- X else {
- X return(1);
- X }
- X}
- X
- XTabInterpolate()
- X{
- X int *ix, *ixy; /*ix, iy, and z are temporary arrays created on the heap*/
- X float *z;
- X
- X int ndata, npair, col, i, j, k, il, ir, newRows, oldRows;
- X int first, found;
- X float x, y, t, u, v, w;
- X long bytesNeeded;
- X char str[cmdWordLen];
- X
- X if( table.header.interpolated ) {
- X ErrMsg("table already interpolated");
- X }
- X if( table.header.rows < 2 ) {
- X ErrMsg("not enough rows");
- X }
- X if( table.header.cols < 2 ) {
- X ErrMsg("not enough cols");
- X }
- X
- X SToR( command.cmdWord[1], &(table.header.samp), FALSE );
- X if (table.header.samp<=0) {
- X table.header.samp = 1.0;
- X ErrMsg("samp must be > 0");
- X }
- X
- X bytesNeeded = 2L * (3+table.header.maxRows);
- X if( (ix=NewPtr(bytesNeeded)) == 0L ) {
- X ErrMsg("not enough free memory");
- X }
- X if( (ixy=NewPtr(bytesNeeded)) == 0L ) {
- X DisposPtr(ix);
- X ErrMsg("not enough free memory");
- X }
- X bytesNeeded = 4L * (3+table.header.maxRows);
- X if( (z=NewPtr(bytesNeeded)) == 0L ) {
- X DisposPtr(ix);
- X DisposPtr(ixy);
- X ErrMsg("not enough free memory");
- X }
- X
- X ndata = 0;
- X first = TRUE;
- X for( i=1; i<=table.header.rows; i++ ) {
- X GetTable(i,1,&x);
- X if (!NaN(&x)) {
- X if( first ) {
- X ndata++;
- X *(ix+ndata) = i;
- X first = FALSE;
- X } /*end if first*/
- X else { /*not first*/
- X ndata++;
- X *(ix+ndata) = i;
- X GetTable( *(ix+ndata-1), 1, &y );
- X if( x<=y ) {
- X DisposPtr(ix);
- X DisposPtr(ixy);
- X DisposPtr(z);
- X ErrMsg("col 1 does not monotonically increase");
- X } /*end if x<=y*/
- X } /*end if not first*/
- X } /*end if not NaN */
- X } /*end for*/
- X
- X if (ndata<2) {
- X DisposPtr(ix);
- X DisposPtr(ixy);
- X DisposPtr(z);
- X ErrMsg("not enough good x-values");
- X }
- X
- X GetTable(*(ix+1),1,&(table.header.start));
- X GetTable( *(ix+ndata), 1, &t );
- X x = 1.0 + ((t-table.header.start)/table.header.samp);
- X oldRows = table.header.rows;
- X if ( ((long)x) > ((long)table.header.maxRows) ) {
- X WriteLine("warning. some data lost from end of columns");
- X newRows = table.header.maxRows;
- X } /*end if*/
- X else {
- X newRows= (int)x;
- X } /*end if*/
- X
- X for (col=2; col<=table.header.cols; col++ ) {
- X npair = 0;
- X for( i=1; i<=ndata; i++ ) {
- X GetTable( *(ix+i), col, &x );
- X if (!NaN(&x)) {
- X npair++;
- X *(ixy+npair) = *(ix+i);
- X } /*end if not NaN*/
- X } /*end for*/
- X
- X if (npair<2) {
- X IToS( col, str );
- X WritePhrase("warning: not enough data in col ");
- X WriteLine(str);
- X table.header.rows = newRows;
- X for( j=1; j<=table.header.rows; j++ ) {
- X SetTable(j,col,infinity,FALSE);
- X }
- X table.header.rows=oldRows;
- X } /*end if pairs<2*/
- X else { /*npairs>=2*/
- X il = 1;
- X ir = 2;
- X for( i=1; i<=newRows; i++ ) {
- X x = table.header.start + table.header.samp*((float)(i-1));
- X if( GetTable(*(ixy+il),1,&t) || (x<t) ) {
- X *(z+i) =infinity;
- X } /*end if (x<t)*/
- X else if( GetTable(*(ixy+npair),1,&t) || (x>t) ) {
- X *(z+i) = infinity;
- X }
- X else if( GetTable(*(ixy+il),1,&t) || GetTable(*(ixy+ir),1,&u) || ((x>=t)&&(x<=u)) ) {
- X GetTable( *(ixy+il), col, &t );
- X GetTable( *(ixy+ir),col, &u );
- X GetTable( *(ixy+il), 1, &v );
- X GetTable( *(ixy+ir), 1, &w );
- X *(z+i) = t + (((u-t)/(w-v))*(x-v));
- X }
- X else { /*search*/
- X j = il+1;
- X found = FALSE;
- X while( (!found) && (j<=(npair-1)) ) {
- X il = j;
- X ir = j+1;
- X GetTable( *(ixy+il), 1, &t );
- X GetTable( *(ixy+ir), 1, &u );
- X if( (x>=t) && (x<=u) ) {
- X found = TRUE;
- X } /*end in interval*/
- X j++;
- X } /*end while*/
- X GetTable( *(ixy+il), col, &t );
- X GetTable( *(ixy+ir),col, &u );
- X GetTable( *(ixy+il), 1, &v );
- X GetTable( *(ixy+ir), 1, &w );
- X *(z+i) = t + (((u-t)/(w-v))*(x-v));
- X } /*end else search*/
- X } /*end for i*/
- X
- X table.header.rows = newRows;
- X for( i=1; i<=table.header.rows; i++ ) {
- X SetTable( i, col, *(z+i), FALSE );
- X } /*end for i*/
- X table.header.rows = oldRows;
- X
- X } /*end if pairs>=2*/
- X } /*end for col*/
- X
- X table.header.interpolated=TRUE;
- X table.header.rows = newRows;
- X Header2Vars();
- X CreateCol1();
- X DisposPtr(ix);
- X DisposPtr(ixy);
- X DisposPtr(z);
- X}
- ________This_Is_The_END________
- if test `wc -l < regio.c` -ne 850; then
- echo 'shar: regio.c was damaged during transit'
- echo ' (should have been 850 bytes)'
- fi
- fi ; : end of overwriting check
- echo 'Extracting regmain.c'
- if test -f regmain.c; then echo 'shar: will not overwrite regmain.c'; else
- sed 's/^X//' << '________This_Is_The_END________' > regmain.c
- X#include "all.h"
- X#include "regtabint.h"
- X
- Xmain()
- X{
- X int t, i, j, k, ii, jj, kk, tBoolean, itop, ileft;
- X Handle TEScrH;
- X int lastEvCoChar, lastEvPrChar;
- X long nBytes, offsetTE, lengthTE;
- X float x, y;
- X char c;
- X GrafPtr savePort;
- X void ScrollUp(), ScrollDown();
- X void TScrollUp(), TScrollDown();
- X Rect tRect, tRect2;
- X char s[cmdWordLen], *gaddr;
- X
- X infinity = 0.0;
- X minfinity = -1.0 / infinity;
- X infinity = 1.0/infinity;
- X nCoeffs = 0;
- X for( i=0; i<33; i++ ) coeffs[i]=0.0;
- X
- X lastEvCoChar = FALSE;
- X lastEvPrChar = FALSE;
- X
- X macVars.numVars = 0;
- X
- X InitGraf(&thePort); /* sets global variables thePort to nil and screenBits to Mac screen */
- X InitFonts();
- X FlushEvents(everyEvent,0);
- X InitWindows();
- X
- X /* set up menus */
- X InitMenus();
- X myMenu[apMenu] = GetMenu(apMenuRes);
- X AddResMenu(myMenu[apMenu],'DRVR'); /* desk accesories */
- X myMenu[fiMenu] = GetMenu(fiMenuRes);
- X myMenu[edMenu] = GetMenu(edMenuRes);
- X myMenu[wiMenu] = GetMenu(wiMenuRes);
- X myMenu[abMenu] = GetMenu(abMenuRes);
- X for ( i = 0; i < lastMenu; i++ )
- X InsertMenu(myMenu[i],0);
- X DrawMenuBar();
- X
- X TEInit();
- X InitDialogs(0L);
- X InitAllPacks();
- X InitPack(stdFile);
- X SetCursor(&arrow);
- X SetRect(&dragRect, 0, 40, 700, 344);
- X SetRect(&growRect, 50, 50, windowWidth, windowHeight);
- X SetRect(&abortRect, 180, 0, 220, 20 );
- X SetRect(&wayOffScreen,1000,1000,1100,1100);
- X doneFlag = FALSE;
- X pendingFlag = FALSE;
- X InitCursor();
- X
- X /* set up graphics window */
- X grPortPtr = &grPort;
- X OpenPort( grPortPtr );
- X SetPort( grPortPtr );
- X grMap.rowBytes = windowWidth / 8 + 1;
- X if( (grMap.rowBytes & 1) != 0 ) grMap.rowBytes++; /* make sure its even */
- X SetRect( &(grMap.bounds), 0, 0, windowWidth, windowHeight );
- X nBytes = grMap.rowBytes * (grMap.bounds.bottom - grMap.bounds.top);
- X grMap.baseAddr = NewPtr(nBytes);
- X grPort.portBits = grMap;
- X grPort.portRect = grMap.bounds;
- X SetPort( grPortPtr );
- X gaddr = (char*) grMap.baseAddr;
- X for( i=0; i<nBytes; i++ ) {
- X *gaddr = '\0';
- X gaddr++;
- X } /*end for*/
- X EraseRect( &(grPort.portRect) );
- X FrameRect( &(grPort.portRect) );
- X
- X SetPort( thePort );
- X
- X /* define windows */
- X
- X theWindow[edWindow] = GetNewWindow( edWndRes, &wRecord[0], -1L );
- X theWindow[prWindow] = GetNewWindow( prWndRes, &wRecord[1], -1L );
- X theWindow[grWindow] = GetNewWindow( grWndRes, &wRecord[2], -1L );
- X theWindow[coWindow] = GetNewWindow( coWndRes, &wRecord[3], -1L );
- X for( i=0; i<lastWindow; i++ ) {
- X theWindow[i]->txFont = 2;
- X vScroll[i] = GetNewControl( 256, theWindow[i]);
- X hScroll[i] = GetNewControl( 257, theWindow[i]);
- X theOrigin[i].h = 0;
- X theOrigin[i].v = 0;
- X topPixel[i] = 1;
- X leftPixel[i] = 1;
- X } /* end for */
- X
- X /* command window */
- X SetPort(theWindow[coWindow]);
- X SetRect(&tRect, 4, 4, 720, 364);
- X tRect2 = theWindow[coWindow]->portRect;
- X IndentRect( &tRect2 );
- X coText = TENew( &tRect, &tRect2 );
- X (*coText)->crOnly = -1;
- X TEInsert("Scientist\'s Helper, Version 2.7, by William Menke\r",50L,coText);
- X TEInsert("Caveat Emptor\r",14L,coText);
- X TEInsert("\r",1L,coText);
- X
- X /* procedure window */
- X SetPort(theWindow[prWindow]);
- X SetRect(&tRect, 4, 4, 720, 364);
- X tRect2 = theWindow[prWindow]->portRect;
- X IndentRect( &tRect2 );
- X prText = TENew( &tRect, &tRect2 );
- X (*prText)->crOnly = -1;
- X TEInsert("label sample\r",13L,prText);
- X TEInsert("prompt \'hi there\'\r",18L,prText);
- X TEInsert("return\r",7L,prText);
- X
- X /*table edit window */
- X SetPort(theWindow[edWindow]);
- X edText = TENew( &wayOffScreen, &wayOffScreen );
- X (*edText)->crOnly = -1;
- X (*edText)->txSize = 10;
- X (*edText)->txFont = geneva;
- X TextFont(geneva);
- X TextSize(10);
- X for( i=0; i<4; i++ ) {
- X SetRect( &(tabEd.name[i]), ((i+1)*100)+1, 1, (i+2)*100, 15 );
- X }
- X for( i=0; i<19; i++ ) {
- X SetRect( &(tabEd.row[i]), 1, ((i+1)*15)+1, 100, (i+2)*15 );
- X }
- X for( i=0; i<19; i++ ) {
- X for( j=0; j<4; j++ ) {
- X SetRect( &(tabEd.entry[i][j]), ((j+1)*100)+1, ((i+1)*15)+1, (j+2)*100, (i+2)*15 );
- X } }
- X tabEd.activeEntry = FALSE;
- X tabEd.activeName = FALSE;
- X
- X LoadSg1(); /*force load of all segments of program*/
- X LoadSg2();
- X LoadSg3();
- X
- X InitTable(); /*initialize table*/
- X WritePhrase("> ");
- X
- X /* initialize procedure info */
- X mem.active = FALSE;
- X mem.stackPtr = -1;
- X mem.numLabels = 0;
- X loops.numLoops = 0;
- X
- X graph.xMin = 0.0;
- X graph.xMax = 1.0;
- X graph.yMin = 0.0;
- X graph.yMax = 1.0;
- X Graph2Vars();
- X
- X currentWindow = -1;
- X scrapIndex = -1;
- X SelectWindow(theWindow[coWindow]);
- X ZeroScrap();
- X setjmp(envbuf);
- X
- X
- X do {
- X
- X SystemTask();
- X
- X if( scrapIndex != (InfoScrap())->scrapCount ) {
- X scrapIndex = (InfoScrap())->scrapCount;
- X lengthTE = GetScrap( TEScrapHndl(), 'TEXT', &offsetTE );
- X if (lengthTE>0) (*((short *) 0x0AB0)) = lengthTE;
- X }
- X
- X GetNextEvent(everyEvent,&myEvent);
- X
- X while ( (*coText)->teLength > maxCoChars ) { /*nips top off of command window if too big*/
- X TECalText(coText);
- X i = (*coText)->selStart;
- X j = (*coText)->selEnd;
- X ii = (*coText)->lineStarts[0];
- X jj = (*coText)->lineStarts[1];
- X t = currentWindow;
- X GetPort( &oldPort );
- X SetPort( theWindow[coWindow] );
- X currentWindow = coWindow;
- X whichWindow = theWindow[currentWindow];
- X TESetSelect( (long)ii, (long)jj, coText );
- X TEDelete( coText );
- X kk = jj - ii;
- X TESetSelect( (long)(i-kk), (long)(j-kk), coText );
- X IfOutScroll(coText);
- X SetPort( oldPort );
- X currentWindow=t;
- X whichWindow = theWindow[currentWindow];
- X }
- X
- X if (mem.active && (!pendingFlag) && (myEvent.what==nullEvent) ) { /*get command line from procedure memory*/
- X mem.stack[ mem.stackPtr ] ++;
- X if (mem.stack[mem.stackPtr] >= (*prText)->nLines ) {
- X ErrMsg( "attempt to read past end of procedure" );
- X } /*end if error*/
- X HLock((*prText)->hText);
- X j=(*prText)->lineStarts[mem.stack[mem.stackPtr]];
- X k=(*prText)->teLength;
- X ExtractLine( *((*prText)->hText), j, k, s );
- X HUnlock((*prText)->hText);
- X CmdFromWnd(s,FALSE);
- X } /*end if procedure is running*/
- X
- X TEIdle(coText);
- X TEIdle(prText);
- X TEIdle(edText);
- X
- X switch(myEvent.what) {
- X case activateEvt:
- X lastEvCoChar=FALSE;
- X lastEvPrChar=FALSE;
- X /* activate events return a window pointer as their message */
- X /* find the window that corresponds to this pointer (if any) */
- X
- X /*cant activate procedure or edit window if procedure is running*/
- X whichWindow = (WindowPtr)myEvent.message;
- X GetWndNumber(whichWindow);
- X if( currentWindow < 0 ) /* window not found */
- X break;
- X SetPort(theWindow[currentWindow]);
- X if (myEvent.modifiers&1) {
- X ShowControl(vScroll[currentWindow]);
- X ShowControl(hScroll[currentWindow]);
- X DrawControls(theWindow[currentWindow]);
- X DrawGrowIcon(theWindow[currentWindow]);
- X if( currentWindow == coWindow ) {
- X TEActivate( coText );
- X }
- X else if( currentWindow == prWindow ) {
- X TEActivate( prText );
- X }
- X else if( (currentWindow==edWindow) &&
- X (tabEd.activeName||tabEd.activeEntry) ) {
- X TEActivate( edText );
- X }
- X }
- X else {
- X if( currentWindow == coWindow ) {
- X TEDeactivate( coText );
- X }
- X else if( currentWindow == prWindow ) {
- X TEDeactivate( prText );
- X }
- X else if( currentWindow == edWindow ) {
- X TEDeactivate( edText );
- X ClipRect( &(whichWindow->portRect) );
- X }
- X HideControl(vScroll[currentWindow]);
- X HideControl(hScroll[currentWindow]);
- X }
- X break;
- X
- X case updateEvt :
- X lastEvCoChar=FALSE;
- X lastEvPrChar=FALSE;
- X
- X GetPort(&savePort);
- X whichWindow = (WindowPtr)myEvent.message;
- X GetWndNumber(whichWindow);
- X if( currentWindow < 0 ) /* window not found */
- X break;
- X SetPort(theWindow[currentWindow]);
- X BeginUpdate(theWindow[currentWindow]);
- X EraseRect(&theWindow[currentWindow]->portRect);
- X DrawWindow();
- X EndUpdate(theWindow[currentWindow]);
- X SetPort(savePort);
- X break;
- X
- X case mouseDown :
- X lastEvCoChar=FALSE;
- X lastEvPrChar=FALSE;
- X
- X /* code returns what type of window */
- X code = FindWindow(pass(myEvent.where), &whichWindow);
- X GetWndNumber(whichWindow);
- X
- X /* determine if this window is up front */
- X if ( whichWindow == FrontWindow() )
- X frontFlag = TRUE;
- X else
- X frontFlag = FALSE;
- X
- X switch(code) {
- X case inMenuBar :
- X DoCommand(MenuSelect(pass(myEvent.where)));
- X break;
- X case inSysWindow :
- X SystemClick(&myEvent,whichWindow);
- X break;
- X case inDrag :
- X if( frontFlag ) {
- X DragWindow(whichWindow,pass(myEvent.where),
- X &dragRect);
- X }
- X else {
- X if( !( (mem.active||pendingFlag) &&
- X ( (currentWindow==prWindow) ||
- X (currentWindow==edWindow) ) ) ) {
- X SelectWindow(whichWindow);
- X }
- X }
- X break;
- X case inGrow :
- X if (frontFlag) {
- X GrowWnd(whichWindow);
- X }
- X else {
- X if( !( (mem.active||pendingFlag) &&
- X ( (currentWindow==prWindow) ||
- X (currentWindow==edWindow) ) ) ) {
- X SelectWindow(whichWindow);
- X }
- X }
- X break;
- X case inContent :
- X if (frontFlag && (currentWindow==coWindow)) {
- X GlobalToLocal(&myEvent.where);
- X MyControl = FindControl(pass(myEvent.where),
- X whichWindow,&whichControl);
- X switch(MyControl) {
- X case inUpButton :
- X TrackControl(whichControl,pass(myEvent.where),
- X TScrollUp);
- X break;
- X case inDownButton :
- X TrackControl(whichControl,pass(myEvent.where),
- X TScrollDown);
- X break;
- X case inPageUp :
- X TPageScroll(MyControl,-6400);
- X break;
- X case inPageDown :
- X TPageScroll(MyControl,6400);
- X break;
- X case inThumb :
- X t = TrackControl(whichControl,pass(myEvent.where),
- X 0L);
- X ScrollBits();
- X break;
- X default:
- X if( (myEvent.modifiers&shiftKey) == 1 )
- X tBoolean = TRUE;
- X else
- X tBoolean = FALSE;
- X TEClick(pass(myEvent.where),tBoolean,coText);
- X } /*end switch MyControl*/
- X } /*end if coWindow*/
- X else if (frontFlag && (currentWindow==grWindow)) {
- X GlobalToLocal(&myEvent.where);
- X MyControl = FindControl(pass(myEvent.where),
- X whichWindow,&whichControl);
- X switch(MyControl) {
- X case inUpButton :
- X TrackControl(whichControl,pass(myEvent.where),
- X ScrollUp);
- X break;
- X case inDownButton :
- X TrackControl(whichControl,pass(myEvent.where),
- X ScrollDown);
- X break;
- X case inPageUp :
- X PageScroll(MyControl,-6400);
- X break;
- X case inPageDown :
- X PageScroll(MyControl,6400);
- X break;
- X case inThumb :
- X t = TrackControl(whichControl,pass(myEvent.where),
- X 0L);
- X ScrollBits();
- X break;
- X default:
- X i = (myEvent.where.h+theOrigin[grWindow].h);
- X j = (myEvent.where.v+theOrigin[grWindow].v);
- X InvGraphScale( i, j, &x, &y );
- X RToS( x, s );
- X currentWindow=coWindow;
- X whichWindow=theWindow[coWindow];
- X SetPort(theWindow[currentWindow]);
- X if(!SetVar("xpos",s)){
- X ErrMsg("couldnt set xpos variable");
- X }
- X WritePhrase(s);
- X WritePhrase(" ");
- X RToS( y, s );
- X if(!SetVar("ypos",s)){
- X ErrMsg("couldnt set ypos variable");
- X }
- X WriteLine(s);
- X currentWindow=grWindow;
- X whichWindow=theWindow[grWindow];
- X SetPort(theWindow[currentWindow]);
- X if(pendingFlag) {
- X currentWindow=grWindow;
- X whichWindow=theWindow[coWindow];
- X SelectWindow(theWindow[coWindow]);
- X PostEvent(keyDown,(long)'\r');
- X longjmp(envbuf,-1);
- X }
- X } /*end switch MyControl */
- X } /*end if grWindow*/
- X else if (frontFlag && (currentWindow==prWindow)) {
- X GlobalToLocal(&myEvent.where);
- X MyControl = FindControl(pass(myEvent.where),
- X whichWindow,&whichControl);
- X switch(MyControl) {
- X case inUpButton :
- X TrackControl(whichControl,pass(myEvent.where),
- X TScrollUp);
- X break;
- X case inDownButton :
- X TrackControl(whichControl,pass(myEvent.where),
- X TScrollDown);
- X break;
- X case inPageUp :
- X TPageScroll(MyControl,-6400);
- X break;
- X case inPageDown :
- X TPageScroll(MyControl,6400);
- X break;
- X case inThumb :
- X t = TrackControl(whichControl,pass(myEvent.where),
- X 0L);
- X ScrollBits();
- X break;
- X default:
- X if( (myEvent.modifiers&shiftKey) == 1 )
- X tBoolean = TRUE;
- X else
- X tBoolean = FALSE;
- X TEClick(pass(myEvent.where),tBoolean,prText);
- X } /*end switch MyControl*/
- X }/*end if prWindow*/
- X else if (frontFlag && (currentWindow==edWindow)) {
- X GlobalToLocal(&myEvent.where);
- X MyControl = FindControl(pass(myEvent.where),
- X whichWindow,&whichControl);
- X switch(MyControl) {
- X case inUpButton :
- X TrackControl(whichControl,pass(myEvent.where),
- X TScrollUp);
- X break;
- X case inDownButton :
- X TrackControl(whichControl,pass(myEvent.where),
- X TScrollDown);
- X break;
- X case inPageUp :
- X TPageScroll(MyControl,-6400);
- X break;
- X case inPageDown :
- X TPageScroll(MyControl,6400);
- X break;
- X case inThumb :
- X t = TrackControl(whichControl,pass(myEvent.where),
- X 0L);
- X ScrollBits();
- X break;
- X default:
- X ileft = (GetCtlValue(hScroll[edWindow])/1024)+1;
- X itop = (GetCtlValue(vScroll[edWindow])/8)+1;
- X ResizePRect();
- X ClipRect( &pRect );
- X if( tabEd.activeName || tabEd.activeEntry ) {
- X /*get text from edit record and delete the text*/
- X HLock((*edText)->hText);
- X i=(*edText)->teLength;
- X ExtractLine( *((*edText)->hText), 0, (i-1), s );
- X HUnlock((*edText)->hText);
- X TEDeactivate(edText);
- X TESetSelect( 0L, (long)i, edText );
- X TEDelete(edText);
- X }
- X if( tabEd.activeName ) {
- X if( GoodCol(tabEd.c)==0 ) {
- X strcpy( table.header.colName[tabEd.c-1], s );
- X }
- X else {
- X SysBeep(5);
- X strcpy( s, " ");
- X }
- X EraseRect( &(tabEd.name[tabEd.c-ileft]) );
- X MoveTo( (tabEd.name[tabEd.c-ileft]).left+1,
- X (tabEd.name[tabEd.c-ileft]).bottom-2 );
- X DrawText( s, 0, strlen(s) );
- X }
- X else if( tabEd.activeEntry ) {
- X if( (GoodCol(tabEd.c)==0) && (GoodRow(tabEd.r)==0) ) {
- X if( table.header.interpolated && (tabEd.c==1) ) {
- X SysBeep(5);
- X GetTable( tabEd.r, 1, &x );
- X RToS(x,s);
- X }
- X else {
- X SToR( s, &x, TRUE );
- X RToS( x, s, TRUE );
- X SetTable( tabEd.r, tabEd.c, x, FALSE );
- X }
- X }
- X else {
- X SysBeep(5);
- X strcpy(s,"");
- X }
- X EraseRect( &(tabEd.entry[tabEd.r-itop][tabEd.c-ileft]) );
- X MoveTo( (tabEd.entry[tabEd.r-itop][tabEd.c-ileft]).left+1,
- X (tabEd.entry[tabEd.r-itop][tabEd.c-ileft]).bottom-2 );
- X DrawText( s, 0, strlen(s) );
- X }
- X tabEd.activeName=FALSE;
- X tabEd.activeEntry=FALSE;
- X for( j=0; j<4; j++ ) {
- X if( PtInRect( pass(myEvent.where), &(tabEd.name[j]) ) ){
- X tabEd.c=ileft+j;
- X tabEd.activeName=TRUE;
- X jj=j;
- X break;
- X } /*end if*/
- X } /*end for*/
- X for( i=0; (i<19)&&(!tabEd.activeName);i++ ) {
- X for( j=0; j<4; j++ ) {
- X if( PtInRect( pass(myEvent.where), &(tabEd.entry[i][j]) ) ) {
- X tabEd.r=itop+i;
- X tabEd.c=ileft+j;
- X tabEd.activeEntry=TRUE;
- X ii=i;
- X jj=j;
- X break;
- X } /*end if*/
- X } } /*end fors*/
- X if( tabEd.activeName ) {
- X if( GoodCol(tabEd.c)!=0 ) {
- X SysBeep(5);
- X tabEd.activeName=FALSE;
- X break;
- X }
- X (*edText)->destRect=tabEd.name[jj];
- X ResizeEdBox();
- X TESetSelect( 0L, (long)(*edText)->teLength, edText );
- X TEDelete(edText);
- X TEInsert( table.header.colName[tabEd.c-1],
- X (long)strlen(table.header.colName[tabEd.c-1]), edText );
- X TESetSelect( 0L, (long)((*edText)->teLength), edText );
- X TEActivate( edText );
- X TEUpdate(&((*edText)->viewRect),edText);
- X }
- X else if( tabEd.activeEntry ) {
- X if( (GoodRow(tabEd.r)!=0) || (GoodCol(tabEd.c)!=0)
- X || ((tabEd.c==1)&&table.header.interpolated) ) {
- X SysBeep(5);
- X tabEd.activeEntry=FALSE;
- X break;
- X }
- X (*edText)->destRect=tabEd.entry[ii][jj];
- X ResizeEdBox();
- X GetTable( tabEd.r, tabEd.c, &x );
- X RToS( x, s );
- X TESetSelect( 0L, (long)(*edText)->teLength, edText );
- X TEDelete(edText);
- X TEInsert( s, (long)strlen(s), edText );
- X TESetSelect( 0L, (long)((*edText)->teLength), edText );
- X TEActivate( edText );
- X TEUpdate(&((*edText)->viewRect),edText);
- X }
- X else {
- X SysBeep(5);
- X }
- X } /*end switch MyControl*/
- X }/*end if edWindow*/
- X else {
- X if( !( (mem.active||pendingFlag) &&
- X ( (currentWindow==prWindow) ||
- X (currentWindow==edWindow) ) ) ) {
- X SelectWindow(whichWindow);
- X }
- X }
- X break;
- X } /* end switch code */
- X break;
- X
- X case keyDown:
- X case autoKey:
- X if( mem.active && (!pendingFlag) ) {
- X break;
- X }
- X c = (char) (myEvent.message & charCodeMask);
- X whichWindow = FrontWindow();
- X GetWndNumber(whichWindow);
- X SetPort(whichWindow);
- X if( ((myEvent.modifiers & cmdKey) != 0)
- X && ((currentWindow==coWindow) || (currentWindow==prWindow)
- X || (currentWindow==grWindow) || (currentWindow==edWindow) )
- X ) {
- X DoCommand( MenuKey(c) );
- X } /*end if cmdkey down*/
- X else if (currentWindow == coWindow) {
- X if( c==(char)3 ) c='\r'; /*enter key is return*/
- X TEKey( c, coText );
- X if( (!lastEvCoChar) || (c=='\r') ) IfOutScroll( coText);
- X if( (c=='\r') &&
- X ((*coText)->selEnd >= ((*coText)->teLength-1)) ) {
- X HLock((*coText)->hText);
- X j=(*coText)->lineStarts[(*coText)->nLines-1];
- X k=(*coText)->teLength-2;
- X ExtractLine( *((*coText)->hText), j, k, s );
- X HUnlock((*coText)->hText);
- X CmdFromWnd(s,TRUE);
- X } /*end if return*/
- X lastEvCoChar=TRUE;
- X lastEvPrChar=FALSE;
- X } /* end if coWindow and frontwindow */
- X else if( (currentWindow==prWindow) && (!pendingFlag) ){
- X if( c==(char)3 ) c='\r'; /*enter key is return*/
- X TEKey( c, prText );
- X if( (!lastEvPrChar) || (c=='\r') ) IfOutScroll( prText );
- X lastEvCoChar=FALSE;
- X lastEvPrChar=TRUE;
- X } /*end if prWindow and frontwindow*/
- X else if( currentWindow==grWindow) {
- X lastEvCoChar=FALSE;
- X lastEvPrChar=FALSE;
- X SysBeep(5);
- X }
- X else if( (currentWindow==edWindow) && (tabEd.activeEntry||tabEd.activeName) ){
- X lastEvCoChar=FALSE;
- X lastEvPrChar=FALSE;
- X ResizePRect();
- X ClipRect( &pRect );
- X if( c==(char)3 ) c='\r'; /*enter key is return*/
- X TEKey( c, edText );
- X if( c=='\r' ) {
- X HLock((*edText)->hText);
- X ExtractLine( *((*edText)->hText), 0, (*edText)->teLength-1, s );
- X HUnlock((*edText)->hText);
- X if( tabEd.activeName ) {
- X strcpy( table.header.colName[tabEd.c-1], s );
- X tabEd.activeName=FALSE;
- X strcpy(s,"");
- X }
- X else if( tabEd.activeEntry ) {
- X SToR( s, &x );
- X SetTable( tabEd.r, tabEd.c, x, FALSE );
- X if (GoodRow(tabEd.r+1)==0) {
- X tabEd.r++;
- X GetTable(tabEd.r,tabEd.c,&x);
- X RToS( x, s );
- X }
- X else {
- X tabEd.activeEntry=FALSE;
- X strcpy(s,"");
- X }
- X SetCtlValue(vScroll[edWindow],GetCtlValue(vScroll[edWindow])+8);
- X }
- X ClipRect( &(whichWindow->portRect) );
- X InvalRect(&(whichWindow->portRect));
- X (*edText)->destRect = wayOffScreen;
- X (*edText)->viewRect = wayOffScreen;
- X TESetSelect( 0L, (long)(*edText)->teLength, edText );
- X TEDelete(edText);
- X TEInsert(s,(long)strlen(s),edText);
- X TESetSelect( 0L, (long)(*edText)->teLength, edText );
- X TEActivate(edText);
- X } /*end if return*/
- X } /* end if edWindow and frontwindow */
- X break;
- X
- X } /* end switch what event */
- X } while ( !(doneFlag=done()) ) ;
- X
- X TEScrH=TEScrapHndl();
- X HLock(TEScrH);
- X ZeroScrap();
- X PutScrap( TEGetScrpLen(), 'TEXT', *TEScrH );
- X HUnlock(TEScrH);
- X scrapIndex = (InfoScrap())->scrapCount;
- X
- X ExitToShell();
- X} /* end main */
- ________This_Is_The_END________
- if test `wc -l < regmain.c` -ne 685; then
- echo 'shar: regmain.c was damaged during transit'
- echo ' (should have been 685 bytes)'
- fi
- fi ; : end of overwriting check
- echo 'Extracting regmanip.c'
- if test -f regmanip.c; then echo 'shar: will not overwrite regmanip.c'; else
- sed 's/^X//' << '________This_Is_The_END________' > regmanip.c
- X#include "all.h"
- X#include "regtabext.h"
- X
- XLoadSg1() /*force load of segment*/
- X{
- X ;
- X}
- X
- XColMin(col, min)
- Xint col;
- Xfloat *min;
- X{
- X int i;
- X float x, y;
- X if (!NextNotNan( 1, col, col, &i ) ){
- X *min=infinity;
- X }
- X else {
- X GetTable(i,col,&x);
- X i++;
- X while( NextNotNan(i,col,col,&i) ) {
- X GetTable(i,col,&y);
- X if (y<x) {
- X x = y;
- X }
- X i++;
- X } /*end while*/
- X *min=x;
- X }
- X}
- X
- XColMax(col,max)
- Xint col;
- Xfloat *max;
- X{
- X int i;
- X float x, y;
- X
- X if (!NextNotNan( 1, col, col, &i ) ) {
- X *max=infinity;
- X }
- X else {
- X GetTable(i,col,&x);
- X i++;
- X while (NextNotNan(i,col,col,&i)) {
- X GetTable(i,col,&y);
- X if (y>x) {
- X x = y;
- X }
- X i++;
- X } /*end while*/
- X *max=x;
- X } /*end if*/
- X}
- X
- XGScan()
- X{
- X int i, j;
- X
- X SToI( command.cmdWord[1], &i );
- X SToI( command.cmdWord[2], &j );
- X if( (GoodCol(i)!=0) || (GoodCol(j)!=0) ) {
- X ErrMsg(noSuchColumn);
- X }
- X ColMin(i,&(graph.xMin));
- X ColMax(i,&(graph.xMax));
- X ColMin(j,&(graph.yMin));
- X ColMax(j,&(graph.yMax));
- X}
- X
- XColMath()
- X{
- X int xcol, ycol, result, i, rows;
- X float x, y;
- X
- X SToI( command.cmdWord[5], &result );
- X rows=table.header.rows;
- X if( (strcmp(command.cmdWord[2],"+")==0) || (strcmp(command.cmdWord[2],"-")==0) ||
- X (strcmp(command.cmdWord[2],"*")==0) || (strcmp(command.cmdWord[2],"/")==0) ) {
- X SToI( command.cmdWord[1], &xcol );
- X SToI( command.cmdWord[3], &ycol );
- X if( strcmp(command.cmdWord[2],"+")==0 ) {
- X for( i=1; i<=rows; i++ ) {
- X GetTable(i,xcol,&x);
- X GetTable(i,ycol,&y);
- X SetTable(i,result,(x+y),FALSE);
- X } /*end for*/
- X }
- X else if( strcmp(command.cmdWord[2],"-")==0 ) {
- X for( i=1; i<=rows; i++ ) {
- X GetTable(i,xcol,&x);
- X GetTable(i,ycol,&y);
- X SetTable(i,result,(x-y),FALSE);
- X } /*end for*/
- X }
- X else if( strcmp(command.cmdWord[2],"*")==0 ) {
- X for( i=1; i<=rows; i++ ) {
- X GetTable(i,xcol,&x);
- X GetTable(i,ycol,&y);
- X if( NaN(&y) ) {
- X SetTable(i,result,infinity,FALSE);
- X }
- X else {
- X SetTable(i,result,(x*y),FALSE);
- X }
- X } /*end for*/
- X }
- X else if( strcmp(command.cmdWord[2],"/")==0 ) {
- X for( i=1; i<=rows; i++ ) {
- X GetTable(i,xcol,&x);
- X GetTable(i,ycol,&y);
- X SetTable(i,result,(x/y),FALSE);
- X } /*end for*/
- X }
- X }
- X else if( (strcmp(command.cmdWord[2],"+#")==0) || (strcmp(command.cmdWord[2],"-#")==0) ||
- X (strcmp(command.cmdWord[2],"*#")==0) || (strcmp(command.cmdWord[2],"/#")==0) ) {
- X SToI( command.cmdWord[1], &xcol );
- X SToR( command.cmdWord[3], &y, TRUE );
- X if (strcmp(command.cmdWord[2],"+#")==0) {
- X for (i=1; i<=rows; i++) {
- X GetTable(i,xcol,&x);
- X SetTable(i,result,(x+y),FALSE);
- X } /*end for*/
- X }
- X else if (strcmp(command.cmdWord[2],"-#")==0) {
- X for (i=1; i<=rows; i++) {
- X GetTable(i,xcol,&x);
- X SetTable(i,result,(x-y),FALSE);
- X } /*end for*/
- X }
- X else if (strcmp(command.cmdWord[2],"*#")==0) {
- X for (i=1; i<=rows; i++) {
- X GetTable(i,xcol,&x);
- X SetTable(i,result,(x*y),FALSE);
- X } /*end for*/
- X }
- X else if (strcmp(command.cmdWord[2],"/#")==0) {
- X for (i=1; i<=rows; i++) {
- X GetTable(i,xcol,&x);
- X if( NaN(&y) ) {
- X SetTable(i,result,infinity,FALSE);
- X }
- X else {
- X SetTable(i,result,(x/y),FALSE);
- X }
- X } /*end for*/
- X }
- X }
- X else if( (strcmp(command.cmdWord[2],"#+")==0) || (strcmp(command.cmdWord[2],"#-")==0) ||
- X (strcmp(command.cmdWord[2],"#*")==0) || (strcmp(command.cmdWord[2],"#/")==0) ) {
- X SToR( command.cmdWord[1], &x );
- X SToI( command.cmdWord[3], &ycol, TRUE );
- X if (strcmp(command.cmdWord[2],"#+")==0) {
- X for (i=1; i<=rows; i++) {
- X GetTable(i,ycol,&y);
- X SetTable(i,result,(x+y),FALSE);
- X } /*end for*/
- X }
- X else if (strcmp(command.cmdWord[2],"#-")==0) {
- X for (i=1; i<=rows; i++) {
- X GetTable(i,ycol,&y);
- X SetTable(i,result,(x-y),FALSE);
- X } /*end for*/
- X }
- X else if (strcmp(command.cmdWord[2],"#*")==0) {
- X for (i=1; i<=rows; i++) {
- X GetTable(i,ycol,&y);
- X SetTable(i,result,(x*y),FALSE);
- X } /*end for*/
- X }
- X else if (strcmp(command.cmdWord[2],"#/")==0) {
- X for (i=1; i<=rows; i++) {
- X GetTable(i,ycol,&y);
- X if( NaN(&y) ) {
- X SetTable(i,result,infinity,FALSE);
- X }
- X else {
- X SetTable(i,result,(x/y),FALSE);
- X }
- X } /*end for*/
- X }
- X }
- X else {
- X ErrMsg(noSuchModifier);
- X }
- X}
- XColFunction()
- X{
- X float x, y;
- X int xcol, ycol, i, rows;
- X
- X SToI( command.cmdWord[2], &xcol );
- X SToI( command.cmdWord[3], &ycol );
- X rows=table.header.rows;
- X if (strcmp(command.cmdWord[1],"sin")==0) {
- X for (i=1; i<=rows; i++) {
- X GetTable( i, xcol, &x );
- X errno = 0;
- X x = (float) sin( (double)x );
- X ToNaN( &x );
- X SetTable( i, ycol, x, FALSE );
- X } /*end for*/
- X }
- X else if (strcmp(command.cmdWord[1],"cos")==0) {
- X for (i=1; i<=rows; i++) {
- X GetTable( i, xcol, &x );
- X errno = 0;
- X x = (float) cos( (double)x );
- X ToNaN( &x );
- X SetTable( i, ycol, x, FALSE );
- X } /*end for*/
- X }
- X else if (strcmp(command.cmdWord[1],"tan")==0) {
- X for (i=1; i<=rows; i++) {
- X GetTable( i, xcol, &x );
- X errno = 0;
- X x = (float) tan( (double)x );
- X ToNaN( &x );
- X SetTable( i, ycol, x, FALSE );
- X } /*end for*/
- X }
- X else if (strcmp(command.cmdWord[1],"asin")==0) {
- X for (i=1; i<=rows; i++) {
- X GetTable( i, xcol, &x );
- X errno = 0;
- X x = (float) asin( (double)x );
- X ToNaN( &x );
- X SetTable( i, ycol, x, FALSE );
- X } /*end for*/
- X }
- X else if (strcmp(command.cmdWord[1],"acos")==0) {
- X for (i=1; i<=rows; i++) {
- X GetTable( i, xcol, &x );
- X errno = 0;
- X x = (float) acos( (double)x );
- X ToNaN( &x );
- X SetTable( i, ycol, x, FALSE );
- X } /*end for*/
- X }
- X else if (strcmp(command.cmdWord[1],"atan")==0) {
- X for (i=1; i<=rows; i++) {
- X GetTable( i, xcol, &x );
- X errno = 0;
- X x = (float) atan( (double)x );
- X ToNaN( &x );
- X SetTable( i, ycol, x, FALSE );
- X } /*end for*/
- X }
- X else if (strcmp(command.cmdWord[1],"exp")==0) {
- X for (i=1; i<=rows; i++) {
- X GetTable( i, xcol, &x );
- X errno = 0;
- X x = (float) exp( (double)x );
- X ToNaN( &x );
- X SetTable( i, ycol, x, FALSE );
- X } /*end for*/
- X }
- X else if (strcmp(command.cmdWord[1],"erf")==0) {
- X for (i=1; i<=rows; i++) {
- X GetTable( i, xcol, &x );
- X errno = 0;
- X errfcn( x, &x,&y,&y,&y,&y );
- X ToNaN( &x );
- X SetTable( i, ycol, x, FALSE );
- X } /*end for*/
- X }
- X else if (strcmp(command.cmdWord[1],"erfc")==0) {
- X for (i=1; i<=rows; i++) {
- X GetTable( i, xcol, &x );
- X errno = 0;
- X errfcn( x, &y,&x,&y,&y,&y );
- X ToNaN( &x );
- X SetTable( i, ycol, x, FALSE );
- X } /*end for*/
- X }
- X else if (strcmp(command.cmdWord[1],"ln")==0) {
- X for (i=1; i<=rows; i++) {
- X GetTable( i, xcol, &x );
- X errno = 0;
- X x = (float) log( (double)x );
- X ToNaN( &x );
- X SetTable( i, ycol, x, FALSE );
- X } /*end for*/
- X }
- X else if (strcmp(command.cmdWord[1],"sqrt")==0) {
- X for (i=1; i<=rows; i++) {
- X GetTable( i, xcol, &x );
- X errno = 0;
- X x = (float) sqrt( (double)x );
- X ToNaN( &x );
- X SetTable( i, ycol, x, FALSE );
- X } /*end for*/
- X }
- X else if (strcmp(command.cmdWord[1],"row")==0) {
- X y = (float)table.header.rows;
- X for (i=1; i<=rows; i++) {
- X GetTable( i, xcol, &x );
- X x = 1.0 + ((x-table.header.start)/table.header.samp);
- X if( x<1.0 ) {
- X x=1.0;
- X }
- X else if( x>y ) {
- X x=y;
- X }
- X SetTable( i, ycol, x, FALSE );
- X } /*end for*/
- X }
- X else {
- X ErrMsg(badModifier);
- X }
- X}
- XInsCommand()
- X{
- X int i, j;
- X SToI( command.cmdWord[2], &i );
- X if( strlen(command.cmdWord[3])==0 ) {
- X strcpy( command.cmdWord[3],"1" );
- X }
- X SToI( command.cmdWord[3], &j );
- X
- X if( strcmp(command.cmdWord[1],"col")==0 ) {
- X InsertCol(i,j);
- X }
- X else if( strcmp(command.cmdWord[1],"row")==0 ) {
- X InsertRow(i,j);
- X }
- X else {
- X ErrMsg( badModifier );
- X }
- X}
- X
- XInsertRow( jRow, many )
- Xint jRow, many;
- X{
- X int nRow, nCol, mRow, mCol, iRow, iCol;
- X float x;
- X
- X nRow = table.header.rows;
- X nCol = table.header.cols;
- X mRow = table.header.maxRows;
- X mCol = table.header.maxCols;
- X
- X if( (nRow+many)>mRow ) {
- X ErrMsg("table would exceed allocated space");
- X }
- X else if (many<=0) {
- X ErrMsg("bad number of rows");
- X }
- X else if (table.header.interpolated) {
- X ErrMsg("cant change row 1 of interpolated table");
- X }
- X else if( GoodRow(jRow)!=0 ) {
- X ErrMsg(noSuchRow);
- X }
- X else {
- X nRow += many;
- X table.header.rows=nRow;
- X for (iRow=nRow; iRow>=(jRow+many); iRow-- ) {
- X for (iCol=1; iCol<=nCol; iCol++) {
- X GetTable((iRow-many),iCol,&x);
- X SetTable(iRow,iCol,x,FALSE);
- X } /*end for iCol*/
- X } /*end for iRow*/
- X for (iRow=1; iRow<=many; iRow++) {
- X for (iCol=1; iCol<=nCol; iCol++) {
- X SetTable( (jRow+iRow-1), iCol, infinity, FALSE );
- X } /*end for iCol*/
- X } /*end for iRow*/
- X Header2Vars();
- X } /*end if*/
- X}
- X
- X
- XInsertCol( jCol, many)
- Xint jCol, many;
- X{
- X int nRow, nCol, mRow, mCol, iRow, iCol;
- X float x;
- X
- X nRow = table.header.rows;
- X nCol = table.header.cols;
- X mRow = table.header.maxRows;
- X mCol = table.header.maxCols;
- X
- X if( (nCol+many)>mCol ) {
- X ErrMsg("table would exceed allocated space");
- X }
- X else if (many<=0) {
- X ErrMsg("bad number of rows");
- X }
- X else if( table.header.interpolated && (jCol=1) ) {
- X ErrMsg("cant change row 1 of interpolated table");
- X }
- X else if( GoodCol(jCol)!=0 ) {
- X ErrMsg( noSuchColumn );
- X }
- X else {
- X nCol += many;
- X table.header.cols=nCol;
- X for (iCol=nCol; iCol>=(jCol+many); iCol--) {
- X strcpy(table.header.colName[iCol-1],table.header.colName[iCol-many-1]);
- X for (iRow=1; iRow<=nRow; iRow++) {
- X GetTable(iRow,(iCol-many),&x);
- X SetTable(iRow,iCol,x,FALSE);
- X } /*end for iRow*/
- X } /*end for iCol*/
- X for (iCol=jCol; iCol<=(jCol+many-1); iCol++ ) {
- X strcpy(table.header.colName[iCol-1],"");
- X for (iRow=1; iRow<=nRow; iRow++) {
- X SetTable( iRow, iCol, infinity, FALSE );
- X } /*end for iRow*/
- X } /*end for iCol*/
- X Header2Vars();
- X } /*end if*/
- X}
- X
- XDelCommand()
- X{
- X int i, j;
- X SToI( command.cmdWord[2], &i );
- X if( strlen(command.cmdWord[3])==0 ) {
- X strcpy( command.cmdWord[3],"1" );
- X }
- X SToI( command.cmdWord[3], &j );
- X
- X if( strcmp(command.cmdWord[1],"col")==0 ) {
- X DeleteCol(i,j);
- X }
- X else if( strcmp(command.cmdWord[1],"row")==0 ) {
- X DeleteRow(i,j);
- X }
- X else {
- X ErrMsg( badModifier );
- X }
- X}
- X
- XDeleteRow( jRow, many)
- Xint jRow, many;
- X{
- X int nRow, nCol, mRow, mCol, iRow, iCol;
- X float x;
- X nRow = table.header.rows;
- X nCol = table.header.cols;
- X mRow = table.header.maxRows;
- X mCol = table.header.maxCols;
- X
- X if (many<=0) {
- X ErrMsg("bad number of rows");
- X }
- X else if( (nRow-jRow+1)<many ) {
- X ErrMsg("attempt to delete off bottom of table");
- X }
- X else if( (nRow-many)<1 ) {
- X ErrMsg("resulting table would have no rows");
- X }
- X else if (table.header.interpolated) {
- X ErrMsg("cant change row 1 of interpolated table");
- X }
- X else if( GoodRow(jRow)!=0 ) {
- X ErrMsg(noSuchRow);
- X }
- X else {
- X nRow -= many;
- X for (iRow=jRow; iRow<=nRow; iRow++) {
- X for (iCol=1; iCol<=nCol; iCol++) {
- X GetTable((iRow+many),iCol,&x);
- X SetTable(iRow,iCol, x,FALSE);
- X } /*end for iCol*/
- X } /*end for iRow*/
- X table.header.rows = nRow;
- X Header2Vars();
- X } /*end if*/
- X}
- X
- XDeleteCol( jCol, many)
- Xint jCol, many;
- X{
- X int nRow, nCol, mRow, mCol, iRow, iCol;
- X float x;
- X
- X nRow = table.header.rows;
- X nCol = table.header.cols;
- X mRow = table.header.maxRows;
- X mCol = table.header.maxCols;
- X
- X if (many<=0) {
- X ErrMsg("bad number of Cols");
- X }
- X else if( (nCol-many)<1 ) {
- X ErrMsg("resulting table would have no columns");
- X }
- X else if( (nCol-jCol+1)<many ) {
- X ErrMsg("attempt to delete of edge of table");
- X }
- X else if( table.header.interpolated && (jCol=1) ) {
- X ErrMsg("cant change row 1 of interpolated table");
- X }
- X else if( GoodCol(jCol)!=0 ) {
- X ErrMsg(noSuchColumn);
- X }
- X else {
- X nCol -= many;
- X for (iCol=jCol; iCol<= nCol; iCol++) {
- X strcpy(table.header.colName[iCol-1],table.header.colName[iCol+many-1]);
- X for( iRow=1; iRow<=nRow; iRow++) {
- X GetTable(iRow,(iCol+many),&x);
- X SetTable(iRow,iCol,x,FALSE);
- X } /*end for iRow*/
- X } /*end for iCol*/
- X table.header.cols = nCol;
- X Header2Vars();
- X } /*end if*/
- X}
- X
- XSwapCommand()
- X{
- X int i, j;
- X SToI( command.cmdWord[2], &i );
- X SToI( command.cmdWord[3], &j );
- X if( strcmp(command.cmdWord[1],"col")==0 ) {
- X SwapCol(i,j);
- X }
- X else if( strcmp(command.cmdWord[1],"row")==0 ) {
- X SwapRow(i,j);
- X }
- X else {
- X ErrMsg( badModifier );
- X }
- X}
- X
- XSwapRow( i, j )
- Xint i, j;
- X{
- X float x, y;
- X int k;
- X
- X for( k=1; k<=table.header.cols; k++ ) {
- X GetTable(i,k,&x);
- X GetTable(j,k,&y);
- X SetTable(i,k,y,FALSE);
- X SetTable(j,k,x,FALSE);
- X }
- X}
- X
- XSwapCol( i, j )
- Xint i, j;
- X{
- X float x, y;
- X int k;
- X char s[cmdWordLen];
- X
- X for( k=1; k<=table.header.rows; k++) {
- X GetTable(k,i,&x);
- X GetTable(k,j,&y);
- X SetTable(k,i,y,FALSE);
- X SetTable(k,j,x,FALSE);
- X }
- X strcpy(s,table.header.colName[i-1]);
- X strcpy(table.header.colName[i-1],table.header.colName[j-1]);
- X strcpy(table.header.colName[j-1],s);
- X}
- X
- XCopyCommand()
- X{
- X int i, j;
- X
- X SToI( command.cmdWord[2], &i );
- X SToI( command.cmdWord[3], &j );
- X if( strcmp(command.cmdWord[1],"col")==0 ) {
- X CopyCol(i,j);
- X }
- X else if( strcmp(command.cmdWord[1],"row")==0 ) {
- X CopyRow(i,j);
- X }
- X else {
- X ErrMsg( badModifier );
- X }
- X}
- X
- XCopyRow( fromRow, toRow)
- Xint fromRow, toRow;
- X{
- X int k;
- X float x;
- X
- X for( k=1; k<=table.header.cols; k++ ) {
- X GetTable(fromRow,k,&x);
- X SetTable(toRow,k,x,FALSE);
- X }
- X}
- X
- XCopyCol( fromCol, toCol )
- Xint fromCol, toCol;
- X{
- X int k;
- X float x;
- X
- X for( k=1; k<=table.header.rows; k++ ) {
- X GetTable(k,fromCol,&x);
- X SetTable(k,toCol,x,FALSE);
- X }
- X strcpy( table.header.colName[toCol-1],table.header.colName[fromCol-1]);
- X}
- XHeader2Vars() /*copy some header variables to macro sub variable table*/
- X /* also redo title of edit window */
- X{
- X int status;
- X char str[120];
- X
- X strcpy( str, "Edit Window for " );
- X strcat( str, table.header.title );
- X if( strlen(str)>35 ) {
- X str[31]='.';
- X str[32]='.';
- X str[33]='.';
- X str[34]='\0';
- X }
- X SetWTitle( theWindow[edWindow], ctop(str) );
- X
- X status = TRUE;
- X if (table.header.interpolated) strcpy( str, "true"); else strcpy( str, "false");
- X status = status && SetVar("interpolated",str);
- X
- X IToS( table.header.rows, str );
- X status = status && SetVar("rows",str);
- X
- X IToS( table.header.cols, str );
- X status = status && SetVar("cols",str);
- X
- X RToS( table.header.start, str );
- X status = status && SetVar("start",str);
- X
- X RToS( table.header.samp, str );
- X status = status && SetVar("samp",str);
- X
- X status = status && SetVar("title",table.header.title);
- X
- X if (!status) {
- X ErrMsg("no space to create header variables");
- X }
- X}
- X
- XCreateCol1() /*fills in column 1*/
- X{
- X int row;
- X
- X if (table.header.interpolated) {
- X for (row=1; row<=table.header.rows; row++ ) {
- X SetTable( row, 1, (table.header.start+table.header.samp*(row-1)), TRUE );
- X } /*end for*/
- X } /*end if*/
- X}
- X
- XInitHeader() /*initializes some header variables*/
- X{
- X int i;
- X char str[80];
- X
- X table.header.interpolated = FALSE;
- X table.header.start = 0.0;
- X table.header.samp = 1.0;
- X strcpy( table.header.title, "");
- X for (i=0; i<table.header.cols; i++ ) {
- X IToS( i, str );
- X strcpy( table.header.colName[i], "Col " );
- X strcat( table.header.colName[i], str );
- X }
- X Header2Vars();
- X}
- X
- XIToS( i, s ) /*integer to string conversion*/
- Xint i;
- Xchar s[];
- X{
- X int j, k;
- X sprintf( s, "%-6d", i );
- X k = strlen( s );
- X for( j=0; j<k; j++ ) { /*clip trailing blanks*/
- X if( s[j]==' ' ) {
- X s[j]='\0';
- X break;
- X }
- X }
- X}
- X
- XRToS( f, s ) /*float to string conversion*/
- Xfloat f;
- Xchar s[];
- X{
- X int j, k;
- X if( (f>-10000.0) && (f<10000.0) ) {
- X ftoa( (double)f, s, 5, 2 );
- X }
- X else {
- X ftoa( (double)f, s, 4, 0 );
- X }
- X for( j=0; j<80; j++ ) { /*clip trailing blanks*/
- X if( s[j]=='\0' ) {
- X break;
- X }
- X else if( s[j]==' ' ) {
- X s[j]='\0';
- X break;
- X } /*end if*/
- X } /*end for*/
- X if( ((s[0]=='+') && (s[1]=='+')) || ((s[0]=='-') && (s[1]=='-')) ) {
- X strcpy( s, "NaN");
- X }
- X}
- X
- XSToR( s, f, NaNsOK ) /*string to float conversion*/
- Xchar s[];
- Xfloat *f;
- Xint NaNsOK;
- X{
- X *f = infinity;
- X sscanf( s, "%e", f );
- X if( (!NaNsOK) && NaN(f) ) {
- X ErrMsg("string to real conversion error");
- X }
- X}
- X
- XSToI( s, i ) /*string to integer conversion*/
- Xchar s[];
- Xint *i;
- X{
- X int error;
- X float f;
- X
- X SToR( s, &f, TRUE );
- X if( (NaN(&f)) || (f<-32767.0) || (f>32767.0) ) {
- X ErrMsg("string to integer conversion error");
- X }
- X else {
- X if( f>0.0 ) {
- X *i = (int)(f+0.5);
- X }
- X else {
- X *i = (int)f;
- X }
- X }
- X}
- X
- XNaN( f ) /*returns TRUE if f is a NaN or +/- Inf*/
- Xfloat *f;
- X{
- X unsigned long mask=017740000000;
- X int e;
- X union bb {
- X unsigned long i;
- X float y;
- X } b;
- X
- X b.y = (*f);
- X e = (int)((b.i&mask)>>23);
- X
- X if( e==255 ) {
- X return(TRUE);
- X }
- X else {
- X return(FALSE);
- X }
- X}
- XVFunctionCommand()
- X{
- X float x, y, z;
- X char vValue[cmdWordLen];
- X
- X SToR( command.cmdWord[2], &x, TRUE );
- X
- X errno = 0;
- X
- X if( strcmp(command.cmdWord[1],"sin")==0 ) {
- X z= sin(x);
- X }
- X else if( strcmp(command.cmdWord[1],"cos")==0 ) {
- X z= cos(x);
- X }
- X else if( strcmp(command.cmdWord[1],"tan")==0 ) {
- X z= tan(x);
- X }
- X else if( strcmp(command.cmdWord[1],"asin")==0 ) {
- X z= asin(x);
- X }
- X else if( strcmp(command.cmdWord[1],"acos")==0 ) {
- X z= acos(x);
- X }
- X else if( strcmp(command.cmdWord[1],"atan")==0 ) {
- X z= atan(x);
- X }
- X else if( strcmp(command.cmdWord[1],"sqrt")==0 ) {
- X z= sqrt(x);
- X }
- X else if( strcmp(command.cmdWord[1],"ln")==0 ) {
- X z= log(x);
- X }
- X else if( strcmp(command.cmdWord[1],"exp")==0 ) {
- X z= exp(x);
- X }
- X else if( strcmp(command.cmdWord[1],"erf")==0 ) {
- X errfcn( x, &z,&y,&y,&y,&y );
- X }
- X else if( strcmp(command.cmdWord[1],"erfc")==0 ) {
- X errfcn( x, &y,&z,&y,&y,&y );
- X }
- X else if( strcmp(command.cmdWord[1],"row")==0 ) {
- X z= ((x-table.header.start)/table.header.samp) + 1.0;
- X if( z<1.0 ) {
- X z=1.0;
- X }
- X else if (z>(float)table.header.rows) {
- X z = (float)table.header.rows;
- X }
- X }
- X else {
- X ErrMsg( noSuchModifier );
- X }
- X if( (errno==EDOM) || (errno==ERANGE) ) {
- X z = infinity;
- X errno=0;
- X }
- X RToS(z, vValue);
- X if( !SetVar(command.cmdWord[3],vValue) ){
- X ErrMsg("couldnt create variable");
- X }
- X}
- X
- XIfCommand()
- X{
- X int i, numLines, comparison;
- X float x, y;
- X comparison = FALSE;
- X
- X if( strlen(command.cmdWord[4])==0 ) {
- X strcpy(command.cmdWord[4],"1");
- X }
- X SToI( command.cmdWord[4], &numLines );
- X if( strcmp(command.cmdWord[2],"s=")==0 ) {
- X if( strcmp(command.cmdWord[1],command.cmdWord[3])==0 ) {
- X comparison=TRUE;
- X }
- X }
- X else if( strcmp(command.cmdWord[2],"s<>")==0 ) {
- X if( strcmp(command.cmdWord[1],command.cmdWord[3])!=0 ) {
- X comparison=TRUE;
- X }
- X }
- X else if( strcmp(command.cmdWord[2],"=")==0 ) {
- X SToR( command.cmdWord[1], &x, TRUE );
- X SToR( command.cmdWord[3], &y, TRUE );
- X if ( NaN(&x) ) x=infinity;
- X if ( NaN(&y) ) y=infinity;
- X if( x==y ) {
- X comparison=TRUE;
- X }
- X }
- X else if( strcmp(command.cmdWord[2],"<>")==0 ) {
- X SToR( command.cmdWord[1], &x, TRUE );
- X SToR( command.cmdWord[3], &y, TRUE );
- X if ( NaN(&x) ) x=infinity;
- X if ( NaN(&y) ) y=infinity;
- X if( x!=y ) {
- X comparison=TRUE;
- X }
- X }
- X else if( strcmp(command.cmdWord[2],"<")==0 ) {
- X if ( NaN(&x) ) x=infinity;
- X if ( NaN(&y) ) y=infinity;
- X SToR( command.cmdWord[1], &x, TRUE );
- X SToR( command.cmdWord[3], &y, TRUE);
- X if( x<y ) {
- X comparison=TRUE;
- X }
- X }
- X else if( strcmp(command.cmdWord[2],">")==0 ) {
- X if ( NaN(&x) ) x=infinity;
- X if ( NaN(&y) ) y=infinity;
- X SToR( command.cmdWord[1], &x, TRUE );
- X SToR( command.cmdWord[3], &y, TRUE );
- X if( x>y ) {
- X comparison=TRUE;
- X }
- X }
- X else if( strcmp(command.cmdWord[2],"<=")==0 ) {
- X if ( NaN(&x) ) x=infinity;
- X if ( NaN(&y) ) y=infinity;
- X SToR( command.cmdWord[1], &x, TRUE );
- X SToR( command.cmdWord[3], &y, TRUE );
- X if( x<=y ) {
- X comparison=TRUE;
- X }
- X }
- X else if( strcmp(command.cmdWord[2],">=")==0 ) {
- X if ( NaN(&x) ) x=infinity;
- X if ( NaN(&y) ) y=infinity;
- X SToR( command.cmdWord[1], &x, TRUE );
- X SToR( command.cmdWord[3], &y, TRUE );
- X if( x>=y ) {
- X comparison=TRUE;
- X }
- X }
- X if( !comparison ) {
- X i = mem.stack[ mem.stackPtr ] + numLines;
- X if( i>=(*prText)->nLines ) {
- X ErrMsg("attempt to jump off end of procedure memory");
- X }
- X mem.stack[mem.stackPtr] = i;
- X }
- X}
- ________This_Is_The_END________
- if test `wc -l < regmanip.c` -ne 910; then
- echo 'shar: regmanip.c was damaged during transit'
- echo ' (should have been 910 bytes)'
- fi
- fi ; : end of overwriting check
- echo 'Extracting regmenu.c'
- if test -f regmenu.c; then echo 'shar: will not overwrite regmenu.c'; else
- sed 's/^X//' << '________This_Is_The_END________' > regmenu.c
- X#include "all.h"
- X#include "regtabext.h"
- X
- XDoCommand(mResult)
- Xunsigned long mResult;
- X{
- X int moveToScrap;
- X Handle TEScrH;
- X char name[30];
- X short theMenu, theItem;
- X Point p;
- X SFReply reply;
- X WindowPtr oldWindow;
- X GrafPtr oldPort;
- X
- X theMenu = mResult >> 16;
- X theItem = mResult;
- X
- X p.h = 100;
- X p.v = 100;
- X
- X moveToScrap = FALSE;
- X
- X switch (theMenu) {
- X
- X case apMenuRes :
- X GetItem(myMenu[0],theItem,name);
- X OpenDeskAcc(name);
- X break;
- X
- X case fiMenuRes :
- X switch(theItem) {
- X case 1: /*read table*/
- X strcpy(name,"RGTB");
- X SFGetFile( pass(p), "\P ", 0L, 1, name, 0L, &reply );
- X ReadTable(&reply);
- X break;
- X case 2: /*write table*/
- X SFPutFile( pass(p), "\PSave Table as . . .", "\PUntitled Table",
- X 0L, &reply );
- X WriteTable(&reply);
- X break;
- X case 4: /*read ascii table*/
- X strcpy( name, "TEXT" );
- X SFGetFile( pass(p), "\P ", 0L, 1, name, 0L, &reply );
- X ReadAsciiTable(&reply);
- X break;
- X case 5: /*write ascii table table*/
- X SFPutFile( pass(p), "\PSave Table as . . . ", "\PUntitled Ascii Table",
- X NULL, &reply );
- X WriteAsciiTable(&reply);
- X break;
- X case 7: /*load procedure*/
- X strcpy( name, "TEXT" );
- X SFGetFile( pass(p), "\P ", 0L, 1, name, 0L, &reply );
- X ReadProcedure(&reply);
- X break;
- X case 8: /*save procedure as*/
- X SFPutFile( pass(p), "\PSave Procedure as . . . ", "\PUntitled Procedure",
- X NULL, &reply );
- X WriteProcedure(&reply);
- X break;
- X case 10: /*MacWrite Graph*/
- X SFPutFile( pass(p), "\PSave graph as . . . ", "\PUntitled Graph",
- X NULL, &reply );
- X WriteGraph(&reply);
- X break;
- X case 12: /* quit */
- X doneFlag = TRUE;
- X break;
- X } /*end switch theItem*/
- X break;
- X
- X case edMenuRes :
- X if( SystemEdit(theItem-1) ) break;
- X oldWindow = whichWindow;
- X whichWindow = FrontWindow();
- X GetPort( &oldPort );
- X GetWndNumber(whichWindow);
- X SetPort( whichWindow );
- X switch(theItem) {
- X
- X case 1: /*undo*/
- X /*undo does nothing*/
- X break;
- X
- X case 3: /*cut*/
- X if( whichWindow == theWindow[coWindow] ) {
- X TECut( coText );
- X moveToScrap=TRUE;
- X }
- X else if (whichWindow == theWindow[prWindow]) {
- X TECut( prText );
- X moveToScrap=TRUE;
- X }
- X else if (whichWindow == theWindow[edWindow]) {
- X TECut( edText );
- X moveToScrap=TRUE;
- X }
- X break;
- X
- X case 4: /*copy*/
- X if( whichWindow == theWindow[coWindow] ) {
- X TECopy( coText );
- X moveToScrap=TRUE;
- X }
- X else if ( whichWindow == theWindow[prWindow]) {
- X TECopy( prText );
- X moveToScrap=TRUE;
- X }
- X else if ( whichWindow == theWindow[edWindow]) {
- X TECopy( edText );
- X moveToScrap=TRUE;
- X }
- X break;
- X
- X case 5: /*paste*/
- X if( whichWindow == theWindow[coWindow] ) {
- X TEPaste( coText );
- X IfOutScroll(coText);
- X }
- X else if (whichWindow == theWindow[prWindow]) {
- X TEPaste( prText );
- X IfOutScroll(prText);
- X }
- X else if (whichWindow == theWindow[edWindow]) {
- X TEPaste( edText );
- X }
- X break;
- X
- X case 6: /*clear*/
- X /*clear does nothing*/
- X break;
- X
- X } /*end switch theItem*/
- X
- X whichWindow = oldWindow;
- X SetPort( oldPort );
- X GetWndNumber(whichWindow);
- X break;
- X
- X case wiMenuRes :
- X switch(theItem) {
- X case 1:
- X SelectWindow(theWindow[coWindow]);
- X break;
- X case 2:
- X SelectWindow(theWindow[grWindow]);
- X break;
- X case 3:
- X SelectWindow(theWindow[prWindow]);
- X break;
- X case 4:
- X SelectWindow(theWindow[edWindow]);
- X break;
- X } /*end switch theItem*/
- X break;
- X
- X case abMenuRes :
- X switch(theItem) {
- X case 1:
- X ErrMsg("Abort!");
- X break;
- X } /*end switch theItem*/
- X break;
- X } /*end switch theMenu*/
- X
- X if (moveToScrap) {
- X TEScrH=TEScrapHndl();
- X HLock(TEScrH);
- X ZeroScrap();
- X PutScrap( TEGetScrpLen(), 'TEXT', *TEScrH );
- X HUnlock(TEScrH);
- X scrapIndex = (InfoScrap())->scrapCount;
- X }
- X
- X HiliteMenu(0);
- X}
- ________This_Is_The_END________
- if test `wc -l < regmenu.c` -ne 178; then
- echo 'shar: regmenu.c was damaged during transit'
- echo ' (should have been 178 bytes)'
- fi
- fi ; : end of overwriting check
- echo 'Extracting regprim.c'
- if test -f regprim.c; then echo 'shar: will not overwrite regprim.c'; else
- sed 's/^X//' << '________This_Is_The_END________' > regprim.c
- X#include "all.h"
- X#include "regtabext.h"
- X
- Xerrfcn( x, erf,erfc,erfci,erfci2, deriv )
- Xfloat x, *erf,*erfc,*erfci,*erfci2, *deriv;
- X/* ERROR FUNCTION AND ASSOCIATED FUNCTIONS */
- X/* X - ARGUMENT OF ERROR FUNCTION. POSITIVE OR NEGATIVE */
- X
- X/* X */
- X/* ERF = 2/SQRT(PI) S EXP( - T**2 ) DT */
- X/* 0 */
- X
- X/* ERFC = 1.0 - ERF */
- X/* ERFCI IS IERFC(X) */
- X/* ERFCI = (1.0/SQRT(PI))*EXP(-X**2)-X(ERFC(X)) */
- X
- X/* ERFCI2 IS I**2ERFC(X) */
- X/* ERFCI2 = 1/4 ((1+2*X**2)ERFC(X)- 2/SQRT(PI)*X*EXP(-X**2)) */
- X/* OR ALTERNATIVELY */
- X/* ERFCI2 = 1/4 (ERCF(X)-2*X*ERFCI(X)) */
- X
- X/* DERIV - D/DX OF ERF(X) */
- X
- X/* METHOD: RATIONAL APPROXIMATION */
- X
- X/* SOURCE: ABRAMOWITZ AND STEGUN, P.299, HANDBOOK OF */
- X/* MATHEMATICAL FUNCTIONS AND CARSLAW AND JAEGER */
- X/* CONDUCTION OF HEAT IN SOLIDS P. 482 */
- X{
- X double t, xx, rat, dexpxx;
- X double derf, dderiv, derfc, derfci, derfci2;
- X double t2,t3,t4;
- X
- X double p=0.3275911, a1=0.254829592, a2=-0.284496736;
- X double a3=1.421413741, a4=-1.453152027, a5=1.061405429;
- X double sqrtpi=1.772453851, pi=3.141592654;
- X
- X xx = fabs( (double) x);
- X dexpxx = exp( -(xx*xx) );
- X if( xx<1.0e-7 ) { /*use first two terms of taylor series expansion*/
- X derf = (2.0 / sqrtpi) * xx * (1.0 - (xx*xx/3.0) );
- X if( x<0.0 ) derf=(-derf);
- X derfc = 1.0 - derf;
- X }
- X else { /*use rational approximation*/
- X t = 1.0 / ( 1.0 + p*xx );
- X t2 = t*t;
- X t3 = t2*t;
- X t4 = t2*t2;
- X rat = (a5*t4 + a4*t3 + a3*t2 + a2*t + a1);
- X derf = 1.0 - t*rat*dexpxx;
- X if (x<0.0) {
- X derf = (-derf);
- X derfc = 2.0 - t*rat*dexpxx;
- X }
- X else {
- X derfc = t*rat*dexpxx;
- X } /*end if*/
- X } /*end if*/
- X xx = (double) x;
- X derfci = (1.0/sqrtpi)*dexpxx-xx*derfc;
- X derfci2 = 0.25 * (derfc-2.0*xx*derfci);
- X dderiv = (2.0*dexpxx)/sqrtpi;
- X
- X *erf = (float) ( derf );
- X *erfc = (float) ( derfc );
- X *erfci = (float) (derfci);
- X *erfci2 = (float) (derfci2);
- X *deriv = (float) ( dderiv );
- X}
- X
- X
- XToNaN(f)
- Xfloat *f;
- X{
- X if( (errno==EDOM) || (errno==ERANGE) ) {
- X *f=infinity;
- X }
- X}
- XSetVar( vName, vValue )
- Xchar vName[], vValue[];
- X/*create entry in macro substitution table and set value*/
- X/*if variable previously exists, it is overwritten */
- X/* returns false if the list is full or if not a valid variable name */
- X/* valid variable names must not contain spaces */
- X
- X{
- X int i, inList;
- X char *index();
- X
- X if ( (strlen(vName)==0) || ((long)index(vName, ' ')!=0L) ) {
- X return(FALSE);
- X }
- X else {
- X inList = FALSE;
- X i = 0;
- X while ( (!inList) && (i<macVars.numVars) ) {
- X if ( strcmp(vName,macVars.inStr[i]) == 0 ) {
- X inList = TRUE;
- X } /*end if inList*/
- X i++;
- X } /*end while*/
- X if (inList) {
- X strcpy( macVars.outStr[i-1], vValue );
- X return( TRUE );
- X }
- X else {
- X if ( (macVars.numVars+1) >= maxVars ) {
- X return( FALSE );
- X }
- X else {
- X strcpy( macVars.inStr[macVars.numVars], vName );
- X strcpy( macVars.outStr[macVars.numVars], vValue );
- X macVars.numVars++;
- X return( TRUE );
- X } /*end if enough space*/
- X } /*end if not inList*/
- X } /*end if valid name*/
- X }
- X
- XDelVar( vName )
- Xchar vName[];
- X/* deletes macro substitution variable from table*/
- X{
- X
- X int i, j, inList;
- X
- X if (macVars.numVars==0) {
- X return( FALSE );
- X }
- X else {
- X inList = FALSE;
- X i = 0;
- X while ( (!inList) && (i<macVars.numVars) ) {
- X if ( strcmp(vName,macVars.inStr[i])==0 ) {
- X inList = TRUE;
- X } /*end if match*/
- X i++;
- X }
- X i--; /*i now points to selected variable*/
- X if (inList) {
- X if (i != (macVars.numVars-1) ) { /*if not last in list, move others*/
- X for ( j=(i+1); j<macVars.numVars; j++ ) {
- X strcpy( macVars.inStr[j-1], macVars.inStr[j] );
- X strcpy( macVars.outStr[j-1], macVars.outStr[j] );
- X }
- X } /*end if*/
- X macVars.numVars--;
- X return( TRUE );
- X } /*end if inList*/
- X else {
- X return( FALSE );
- X } /*end if not inList */
- X } /*end if list not empty*/
- X}
- X
- XListVars()
- X/* list macro substitution table */
- X{
- X int i;
- X
- X for( i=0; i<macVars.numVars; i++ ) {
- X CheckAbortMenu();
- X WritePhrase( "\'" );
- X WritePhrase( macVars.inStr[i] );
- X WritePhrase( "\' \'" );
- X WritePhrase( macVars.outStr[i] );
- X WriteLine( "\'" );
- X } /* end for */
- X}
- X
- XSBreak( command, macrosOn )
- XcommandRec *command;
- Xint macrosOn;
- X/* breaks command string into command words that are separated by blanks */
- X/* quoted blanks not broken */
- X/* macro substitutions performed on all command words if macrosOn true */
- X{
- X int i, j, ibuf, len;
- X char c[2];
- X int quote, word, error, status;
- X
- X for( i=0; i<numCmdWds; i++ ) {
- X strcpy( command->cmdWord[i], "" ); /*set command words to null*/
- X }
- X
- X i = 0;
- X j = 0;
- X quote = FALSE;
- X word = FALSE;
- X error = FALSE;
- X ibuf = 0;
- X if( (len=strlen(command->cmdStr))==0) {
- X return(TRUE);
- X }
- X
- X c[1] = '\0';
- X while ( (ibuf<len) && (!error) ) {
- X if ( i >= cmdWordLen ) {
- X error = TRUE;
- X }
- X else {
- X c[0] = command->cmdStr[ibuf];
- X if( j >= numCmdWds ) {
- X error = TRUE;
- X }
- X else if ( ((c[0]==' ')||(c[0]=='\t')) && (!quote) ) {
- X if (word) {
- X word = FALSE;
- X i = 0;
- X j++;
- X }
- X }
- X else if ( (c[0]==' ')||(c[0]=='\t') && quote ) {
- X word = TRUE;
- X strcat( command->cmdWord[j], c );
- X i++;
- X }
- X else if ( (c[0]=='\'') && (!quote) ) {
- X word = TRUE;
- X quote = TRUE;
- X }
- X else if ( (c[0]=='\'') && quote ) {
- X word = FALSE;
- X quote = FALSE;
- X i = 0;
- X j++;
- X }
- X else {
- X word = TRUE;
- X strcat( command->cmdWord[j], c );
- X i++;
- X } /*end if on characters*/;
- X } /*end if cmdWordLen*/
- X ibuf++;
- X } /*end while*/;
- X
- X status = FALSE;
- X if ( !error ) {
- X i = 0;
- X status = TRUE;
- X while ( (i<numCmdWds) && status && macrosOn ) {
- X status = GetVar( command->cmdWord[i], command->cmdWord[i] );
- X i++;
- X } /*while numCmdWds*/;
- X } /*if not error*/
- X
- X return( (!error) && status );
- X}
- X
- XGetVar( vName, vValue)
- Xchar vName[], vValue[];
- X/* does macro-substitution on a variable reference*/
- X/* does not change the value of VValue on no-match*/
- X/* returns false only if no match occurs on a valid variable name*/
- X/* where a valid variable reference*/
- X/* a) starts with a @ */
- X/* b) contains no spaces */
- X
- X{
- X int i, len;
- X int inList;
- X char *index();
- X
- X if( ((long)index(vName,' ')!=0L) || ((long)index(vName,'@')!=(long)vName) ) {
- X /*not a variable reference*/
- X return(TRUE);
- X }
- X else if ( (len=strlen(vName)) < 2 ) { /*string consisting only of @ is invalid*/
- X return(FALSE);
- X }
- X else if (macVars.numVars==0) { /*is valid reference but no variables defined*/
- X return(FALSE);
- X }
- X else { /* is a valid variable reference */
- X inList = FALSE;
- X i = 0;
- X while ( (!inList) && (i<macVars.numVars) ) {
- X if (strcmp( &(vName[1]) , macVars.inStr[i] ) == 0) {
- X inList = TRUE;
- X } /*end if*/
- X i++;
- X } /*end while*/
- X if (inList) {
- X strcpy( vValue, macVars.outStr[i-1] );
- X return(TRUE);
- X } /*end if inList*/
- X else {
- X return(FALSE);
- X } /*end if not inList*/
- X } /* end if valid reference*/
- X}
- X
- Xdone()
- X{
- X if( doneFlag ) {
- X if( CautionAlert(quitAlertRes, NULL)==1 ) {
- X return(TRUE);
- X }
- X else {
- X return(FALSE);
- X }
- X }
- X else {
- X return(FALSE);
- X }
- X}
- X
- XGoodRow( row ) /* returns 0 if 1<=row<=rows, 1 if rows<row<=maxrows, 2 otherwise */
- Xint row;
- X{
- X if( (row>=1) && (row<=table.header.rows) ) {
- X return(0);
- X }
- X else if( (row>table.header.rows) && (row<=table.header.maxRows) ) {
- X return(1);
- X }
- X else {
- X return(2);
- X }
- X}
- X
- XGoodCol( col ) /* returns 0 if 1<=col<=cols, 1 if cols<col<=maxcols, 2 otherwise */
- Xint col;
- X{
- X if( (col>=1) && (col<=table.header.cols) ) {
- X return(0);
- X }
- X else if( (col>table.header.cols) && (col<=table.header.maxCols) ) {
- X return(1);
- X }
- X else {
- X return(2);
- X }
- X}
- X
- XErrMsg( message )
- Xchar message[];
- X{
- X int i;
- X char s[80];
- X
- X HiliteMenu(0);
- X RedoEditWindow();
- X if( currentWindow!=coWindow ) {
- X SetPort(theWindow[coWindow]);
- X SelectWindow( theWindow[coWindow] );
- X currentWindow = coWindow;
- X whichWindow = theWindow[coWindow];
- X }
- X (*coText)->selStart = (*coText)->teLength;
- X (*coText)->selEnd = (*coText)->teLength;
- X TEInsert( "Error: ", 7L, coText );
- X TEInsert( message, (long)strlen(message), coText );
- X TEInsert( "\r", 1L, coText );
- X if( mem.active ) { /*turn off procedure*/
- X TESetSelect( (long)((*prText)->lineStarts[mem.stack[mem.stackPtr]]),
- X (long)((*prText)->lineStarts[mem.stack[mem.stackPtr]+1]),
- X prText );
- X pendingFlag=FALSE;
- X NoPendingInput();
- X for (i=mem.stackPtr; i>=0; i-- ) {
- X IToS( mem.stack[i]+1, s );
- X TEInsert("called from line ",17L,coText);
- X TEInsert(s, (long)strlen(s), coText );
- X TEInsert("\r", 1L, coText);
- X }
- X mem.active=FALSE;
- X mem.stackPtr=-1;
- X loops.numLoops=0;
- X }
- X TEInsert( "> ", 2L, coText );
- X IfOutScroll( coText );
- X SysBeep(5);
- X longjmp(envbuf,-1);
- X}
- X
- XWriteLine( message )
- Xchar message[];
- X{
- X if( currentWindow!=coWindow ) {
- X SetPort(theWindow[coWindow]);
- X SelectWindow( theWindow[coWindow] );
- X currentWindow = coWindow;
- X whichWindow = theWindow[coWindow];
- X }
- X (*coText)->selStart = (*coText)->teLength;
- X (*coText)->selEnd = (*coText)->teLength;
- X TEInsert( &message[0], (long)strlen(message), coText );
- X TEInsert( "\r", 1L, coText );
- X IfOutScroll( coText );
- X}
- X
- XWritePhrase( message )
- Xchar message[];
- X{
- X if( currentWindow!=coWindow ) {
- X SetPort(theWindow[coWindow]);
- X SelectWindow( theWindow[coWindow] );
- X currentWindow = coWindow;
- X whichWindow = theWindow[coWindow];
- X }
- X (*coText)->selStart = (*coText)->teLength;
- X (*coText)->selEnd = (*coText)->teLength;
- X TEInsert( &message[0], (long)strlen(message), coText );
- X IfOutScroll( coText );
- X}
- X
- X
- XCheckAbortMenu()
- X{
- X Point mPoint;
- X if (Button() != 0) {
- X GetMouse( &mPoint );
- X LocalToGlobal( &mPoint );
- X if( PtInRect( pass(mPoint), &abortRect ) != 0 ) {
- X SysBeep(20);
- X SetPort(theWindow[coWindow]);
- X SelectWindow( theWindow[coWindow] );
- X currentWindow = coWindow;
- X whichWindow = theWindow[coWindow];
- X if( mem.active ) { /*turn off procedure*/
- X mem.active=FALSE;
- X mem.stackPtr=-1;
- X loops.numLoops=0;
- X pendingFlag=FALSE;
- X NoPendingInput();
- X }
- X TEInsert( "Abort!\r",7L,coText);
- X TEInsert( "> ", 2L, coText );
- X IfOutScroll( coText );
- X RedoEditWindow();
- X HiliteMenu(0);
- X longjmp(envbuf,-1);
- X } /*end if abort menu and item*/
- X } /*end if mouse is down*/
- X HiliteMenu(0);
- X}
- XPendingInput()
- X{
- X DisableItem( myMenu[apMenu], 0 );
- X DisableItem( myMenu[fiMenu], 1 );
- X DisableItem( myMenu[fiMenu], 4 );
- X DisableItem( myMenu[fiMenu], 7 );
- X DisableItem( myMenu[edMenu], 0 );
- X DisableItem( myMenu[wiMenu], 3 );
- X DisableItem( myMenu[wiMenu], 4 );
- X}
- X
- XNoPendingInput()
- X{
- X EnableItem( myMenu[apMenu], 0 );
- X EnableItem( myMenu[fiMenu], 1 );
- X EnableItem( myMenu[fiMenu], 4 );
- X EnableItem( myMenu[fiMenu], 7 );
- X EnableItem( myMenu[edMenu], 0 );
- X EnableItem( myMenu[wiMenu], 3 );
- X EnableItem( myMenu[wiMenu], 4 );
- X}
- X
- XGraph2Vars()
- X{
- X int status;
- X char s[cmdWordLen];
- X
- X RToS( graph.xMin, s );
- X status = SetVar( "xmin", s );
- X
- X RToS( graph.xMax, s );
- X status = status && SetVar( "xmax", s );
- X
- X RToS( graph.yMin, s );
- X status = status && SetVar( "ymin", s );
- X
- X RToS( graph.yMax, s );
- X status = status && SetVar( "ymax", s );
- X
- X if( !status ) {
- X ErrMsg("couldnt create graphics variables");
- X }
- X}
- X
- XFindLabel( s, line) /*search for particular label and return its line number*/
- Xchar s[];
- Xint *line;
- X{
- X commandRec tCommand;
- X int i, j, k, match;
- X
- X match = FALSE;
- X *line = 0;
- X for( i=0; (i<mem.numLabels && (!match)); i++) { /*search label list*/
- X j=(*prText)->lineStarts[mem.labels[i]];
- X k=((*prText)->teLength)-1;
- X HLock((*prText)->hText);
- X ExtractLine( *((*prText)->hText), j, k, tCommand.cmdStr );
- X HUnlock((*prText)->hText);
- X if( !SBreak( &tCommand, FALSE ) ) {
- X WriteLine("(find) bad line in procedure:");
- X /*ErrMsg(tCommand.cmdStr);*/
- X }
- X if (strcmp(tCommand.cmdWord[1],s)==0) {
- X match = TRUE;
- X *line = mem.labels[i];
- X }
- X } /*end for*/
- X return( match );
- X}
- X
- XListLabels() /*constructs label list from current contents of procedure memory*/
- X{
- X commandRec tCommand;
- X int i, j, k, badLine;
- X
- X mem.numLabels = 0;
- X badLine=FALSE;
- X for( i=0; i<(*prText)->nLines; i++) {/*scan memory sequentially*/
- X j=(*prText)->lineStarts[i];
- X k=((*prText)->teLength)-1;
- X HLock((*prText)->hText);
- X ExtractLine( *((*prText)->hText), j, k, tCommand.cmdStr );
- X HUnlock((*prText)->hText);
- X if( !SBreak( &tCommand, FALSE ) ) {
- X TESetSelect( (long)((*prText)->lineStarts[i]), (long)((*prText)->lineStarts[i+1]),
- X prText );
- X WriteLine("bad line in procedure:");
- X WriteLine(tCommand.cmdStr);
- X badLine=TRUE;
- X }
- X if( strcmp(tCommand.cmdWord[0],"label")==0 ) {
- X mem.labels[mem.numLabels] = i;
- X mem.numLabels++;
- X }
- X } /*end for*/
- X if( badLine ) {
- X ErrMsg("procedure aborted");
- X }
- X}
- X
- XExtractLine(c, start, end, cc)
- Xchar c[];
- Xint start, end;
- Xchar cc[];
- X{
- X int i;
- X for( i=0; ( (i<(end-start+1)) && (i<(cmdWordLen-1)) ); i++ ) {
- X cc[i] = c[i+start];
- X if (cc[i]=='\r') {
- X cc[i] = '\0';
- X break;
- X }
- X }
- X cc[i] = '\0';
- X}
- X
- XRedoEditWindow()
- X{
- X GrafPtr oldPort;
- X int oldWindow;
- X
- X GetPort( &oldPort );
- X oldWindow=currentWindow;
- X
- X SetPort( theWindow[edWindow] );
- X InvalRect( &(theWindow[edWindow]->portRect) );
- X tabEd.activeName=FALSE;
- X tabEd.activeEntry=FALSE;
- X
- X SetPort( oldPort );
- X currentWindow=oldWindow;
- X whichWindow=theWindow[currentWindow];
- X}
- X
- X
- X
- X
- X
- ________This_Is_The_END________
- if test `wc -l < regprim.c` -ne 577; then
- echo 'shar: regprim.c was damaged during transit'
- echo ' (should have been 577 bytes)'
- fi
- fi ; : end of overwriting check
- echo 'Extracting regtab.m'
- if test -f regtab.m; then echo 'shar: will not overwrite regtab.m'; else
- sed 's/^X//' << '________This_Is_The_END________' > regtab.m
- Xln regmain.o regcmdloop.o regproc.o regmenu.o regtable.o lib/sacroot.o -lm -lc \
- X+O regmanip.o regprim.o -lm -lc \
- X+O reggauss.o regspline.o -lm -lc \
- X+O regwnd.o regio.o reggraph.o regseries.o -lm -lc -o regtab.code
- Xrgen regtab.r
- Xsetbundle
- X
- X
- ________This_Is_The_END________
- if test `wc -l < regtab.m` -ne 8; then
- echo 'shar: regtab.m was damaged during transit'
- echo ' (should have been 8 bytes)'
- fi
- fi ; : end of overwriting check
- exit 0
-