#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 3 (of 4)."
# Contents:  ./Doc/Output.doc ./Ldh/ldhfit.c ./Ldh/ldhfit.test2
#   ./Ldh/ldhfit.testx ./Lib/simpdev.c ./Lib/simpinput.c
#   ./Lib/simpmain.c
# Wrapped by local@rupley on Wed Nov 21 00:31:09 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f './Doc/Output.doc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'./Doc/Output.doc'\"
else
echo shar: Extracting \"'./Doc/Output.doc'\" \(6063 characters\)
sed "s/^X//" >'./Doc/Output.doc' <<'END_OF_FILE'
X DESCRIPTION OF OUTPUT
X
X
J. A. Rupley, Tucson, Arizona
X
X
X
RESULTS
X
At various stages of the fitting, determined by the control values
prt_cycle and quad_test and by command line options, the parameter and
data arrays and other results are displayed on the crt terminal and
stored on disk.
X
X This output is explained here.  The description is for LDHFIT, but it
holds, except for some special values given at the end of the data
display, for any function fit by use of the simplex fitting routines.
X
X(1) SIMPLEX:  for each vertex of the simplex, the least squares function
value (the weighted sum of squares of the residuals) is displayed, then
one or more lines of values (four values per line), giving in order the
current values of the parameters.  The number of vertices is one greater
than the number of free parameters.  Fixed parameters show the same
value for all vertices.
X
NOTE:  for some (most?) displays, such as the above, the count of
vertices or parameters starts with ordinal 0.
X
X(2) CENTROID OF THE SIMPLEX:  the least squares function value is given,
then the current values of the parameters.  The centroid is the average
of the vertices of the simplex and is the preferred set of estimates of
the best-fit parameter values.  These estimates are used in calculation
of values of the dependent variable, Ycalculated(i), for each data
point, and in various calculations special for the LDHFIT model.
X
X(3) EXIT TESTING:  immediately following the centroid listing, one line
gives the mean of the least squares function values, the root mean
square deviation of the function values from the mean, and the test
value = rms deviation/mean.  When the test value is less than the
control value exit_test, generally set at 0.00000001, fitting is
complete.
X
X(4) RMS ERROR:  the root mean square weighted error of the fit is the
square root of the quantity:  the least squares function value at the
centroid divided by the number of data points less the number of free
parameters ( RMS ERROR = SQRT(CENTROID SSQ/(# DATA - # FREE PARAMETERS).
The rms error is useful as a test for the quality of the fit (i.e., of
the deviations between observed and calculated values of the dependent
variable).  The rms error should be no greater than the expected
uncertainty in the data.  If it is greater than expectation, the fit may
be unsatisfactory.  The rms error can also be used as a test for flyers
among the data points.  A deviation of 3 x rms error between the
observed and calculated values is sufficient to suggest dropping a data
point from the fitting.
X
X(5) DATA AND CALCULATED VALUES:  for each data point are listed in order
the values of:  Yobserved(i), which for LDHFIT is the initial reaction
rate measured and entered into the program as data; Ycalculated(i) =
Ymodel(i), which is the initial reaction rate calculated with the model
equation and the best-fit parameter values of the centroid; Yobserved(i)
X- Ycalculated(i), which is the deviation between observation and
calculation; the statistical weight of the data point, here set
generally at unity; and the values for the data point of the independent
variables, which for LDHFIT are in order the concentrations of NADH,
pyruvate, and lactate (a, b, and p).  The format of this output is given
in the function "fdatprint()".
X
X(6) OTHER VALUES CALCULATED FROM THE BEST-FIT PARAMETERS:  following the
display of the data, various other values are displayed, as specified in
the function "fpointprint()".  For LDHFIT:  (a) the coordinates of
points that can be used to draw the lines of the primary and secondary
reciprocal plots of the steady-state kinetic analysis; (b) values of the
parameters, a variation of the listing under CENTROID.
X
X(7) QUADRATIC FIT:  at intervals determined by the control value
quad_test, quadratic fitting of the least squares function surface is
carried out, to reconstruct the simplex and to obtain standard
deviations of the free parameters.  There is considerable screen display
that allows tracking of the process.  The file "simplex.doc" explains
this output.  The quadratic fit may fail, and often does in the early
stages of fitting.  Failure is indicated by explicit error messages or
by zero or negative values of variables.  If the quadratic fit fails,
the values of the Q MATRIX DIAGONAL and B MATRIX DIAGONAL can be helpful
in deciding what to do, e.g., whether to fix a parameter.
X
X (8) STANDARD DEVIATIONS FOR THE FREE PARAMETERS:  at the end of the
quadratic fit display, a table gives estimates of the standard
deviations of the free parameters.  Following this table, the vertices
of the reconstructed simplex are given.  Further minimization starts
with this simplex.  If y-pmin is less than yzero = ycentroid, the
parameter values at pmin, an improved estimate, are inserted as one of
the vertices of the reconstructed simplex.  This procedure can speed up
convergence.
X
X
X
MINIMIZATION
X
In each iteration of the Nelder-Mead method, the vertex with the highest
least squares function value is adjusted to give a lower value.  The
output displayed at each cycle allows one to track this process.
X
X (1) One line giving in order:  the number of the cycle, the values of
the least squares function before adjustment and after adjustment, and
the adjustment operation.
X
X (2) One or more lines giving the parameter values of the vertex before
adjustment.
X
X (3) One or more lines giving the parameter values after adjustment.
X
X (4) One or more lines giving the parameter values of the centroid of
the simplex.
X
X (5) One line giving the mean and rms deviation of the function values
of all the vertices of the simplex after the adjustment, and the test
value rms deviation/mean.
X
X (6) One line giving the rms error of the current best fit to the data.
X
X (7) Optionally, depending on the code in "fspecial()", one or more lines
of messages giving, for example, the error(s) in calculation of y-pmin during
the last cycle of quadratic fit, the next iteration for display of the
simplex (maxiter), the next iteration for quadratic fitting (quad_test),
etc.
END_OF_FILE
if test 6063 -ne `wc -c <'./Doc/Output.doc'`; then
    echo shar: \"'./Doc/Output.doc'\" unpacked with wrong size!
fi
# end of './Doc/Output.doc'
fi
if test -f './Ldh/ldhfit.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'./Ldh/ldhfit.c'\"
else
echo shar: Extracting \"'./Ldh/ldhfit.c'\" \(6480 characters\)
sed "s/^X//" >'./Ldh/ldhfit.c' <<'END_OF_FILE'
X/* LDHFIT.C */
X/*-
VERSION OF XXXXFIT, for:
X  
nonlinear least squares fit by simplex minimizaton (Nelder-Mead algorithm).
X  
analysis of lactate dehydrogenase initial rate kinetic data:
X	two substrate -- two product mechanism,
X	with inhibition by first product,
X	and with reactant and product abortive complexes;
X  
see DATA_REDN.DOC for description of rate law.
X */
X/*-
contents of the XXXXFIT module  =  
declarations and routines for simplex fitting special to function to be fit
X(no other functions/files need to be rewritten or adapted for a new model):
X  
X	mnemonic defines for members of data and parameter structures
X  
X	function for calculation of dependent variable and
X		weighted sum of residuals squared		= func()
X  
X	print of <data> records					= fdatprint()
X  
X	additional display called by fdatprint(), 
X		specially written for this model 		= fpointprint()
X  
X	customizable display called by <simpfit()>, 
X		following the output tracking each cycle
X		of minimization					= fspecial()
X  
J.A. Rupley, Tucson, Arizona
rupley!local@megaron.arizona.edu
X*/
X
X#define XXXXFIT
X
X#include "simpdefs.h"		/* externals are read from <simpdefs> */
X
X/* DEFINES SPECIAL TO FITTING FUNCTION */
X
X#define Y	0		/* defines for elements of struct dat */
X#define YC	1		/* (mnemonic) */
X#define W	2
X#define A	3
X#define B	4
X#define P	5
X
X#define VMAX	0		/* defines for elements of struct pstruct */
X#define KMA	1		/* (mnemonic) */
X#define KMB	2
X#define KMAB	3
X#define KMQ_KMPQ 4
X#define KIP_1	5
X#define KIB_K3K4 6
X
X/*-
XFUNC
X	CALCULATION OF LEAST SQUARES FUNCTION
X	CODED ACCORDING TO MODEL BEING FIT
X	IT SHOULD BE EFFICIENT
X	DURING THE FIT, TIME IS MOSTLY SPENT HERE
X*/
X
int
func(g)
X	struct pstruct *g;
X{
X	register int    n;
X
X	extern struct dat data[];
X	extern int      nparm;
X	extern int      ndata;
X
X	/* bounds checks */
X	for (n = 0; n < nparm; n++)
X		if (g->parm[n] <= 0) {
X			/* if bound violated, set function value HUGE */
X			/* and return ERROR */
X			g->val = 1.E38;
X			fprintf(stderr, "function error\n");
X			return (ERROR);
X		}
X	g->val = 0;
X	for (n = 0; n < ndata; n++) {
X		/* evaluation of dependent variable */
X		data[n].datval[YC] =
X			g->parm[VMAX] /
X			(
X			 1 + g->parm[KMQ_KMPQ] * data[n].datval[P]
X			 + g->parm[KMA] / data[n].datval[A]
X			 + g->parm[KMB] / data[n].datval[B]
X			 * (1 + g->parm[KMQ_KMPQ] * data[n].datval[P])
X			 * (1 + g->parm[KIP_1] * data[n].datval[P])
X		     + g->parm[KMAB] / data[n].datval[A] / data[n].datval[B]
X			 * (1 + g->parm[KMQ_KMPQ] * data[n].datval[P])
X			 + g->parm[KIB_K3K4] * data[n].datval[B]
X			);
X		/* evaluation of weighted sum of residuals squared */
X		g->val = g->val + (data[n].datval[Y] - data[n].datval[YC])
X			* (data[n].datval[Y] - data[n].datval[YC])
X			* data[n].datval[W]
X			* data[n].datval[W];
X	}
X	return (OK);
X}				/* END OF FUNC        			 */
X
X/*-
XFDATPRINT
X	PRINT DATA AND COMPARE WITH CALCULATED VALUES
X	CODED ACCORDING TO MODEL AND DATA
X*/
X
void
fdatprint(fptr)
X	FILE           *fptr;
X{
X	register int    j;
X
X	extern int      iter, ndata, maxiter;
X	extern struct dat data[];
X	extern char     title[];
X
X	extern void     fpointprint();
X
X	fprintf(fptr, "\1\f\n%-s\n\niteration number %d\n\n", title, iter);
X	fprintf(fptr,
X		"        yobs   ycalc   del-y  weight       a         b         p\n");
X	for (j = 0; j < ndata; j++)
X		fprintf(fptr,
X			"%4d %7.3f %7.3f %7.3f %7.3f %10.5f %10.5f %10.5f\n",
X			(j + 1), data[j].datval[Y], data[j].datval[YC], (data[j].datval[Y] - data[j].datval[YC]),
X			data[j].datval[W], data[j].datval[A], data[j].datval[B], data[j].datval[P]);
X
X	if (maxiter != 0)
X		fpointprint(fptr);
X}				/* END OF FDATPRINT			 */
X
X/*-
XFPOINTPRINT
X	PRINT POINTS FOR CONSTRUCTION OF PRIMARY AND SECONDARY PLOTS
X	CODED ACCORDING TO MODEL AND DATA
X*/
X
void
fpointprint(fptr)
X	FILE           *fptr;
X{
X
X	extern struct pstruct pcent;
X	extern char     title[];
X	extern int      iter;
X	double          v, k1, k2, k3, k4, k5, vint, v1, v2, s1, s2;
X
X	v = pcent.parm[VMAX];
X	k1 = pcent.parm[KMA];
X	k2 = pcent.parm[KMB];
X	k3 = pcent.parm[KMAB];
X	k4 = pcent.parm[KMQ_KMPQ];
X	k5 = pcent.parm[KIP_1];
X	vint = (1 - k1 * k2 / k3) / v;
X	v1 = (1 + k1 /.035) / v;
X	v2 = v1 + k4 * 150 / v;
X	s1 = (k2 + k3 /.035) / v;
X	s2 = (s1 + k2 * k5 * 150 / v) * (1 + k4 * 150);
X
X	fprintf(fptr, "\1\f\n%-s\n\niteration number %d\n\n", title, iter);
X	fprintf(fptr,
X		"For primary plot at fixed b = [Pyruvate]:\n");
X	fprintf(fptr,
X		"intersection (1/a = 1/[NADH], 1/V)      %10.2f%10.2f\n", -k2 / k3, vint);
X	fprintf(fptr,
X		"1/V intercepts at b = (.7,.35,.22,.15)      %8.2f%8.2f%8.2f%8.2f\n\n",
X		(1 + k2 /.7) / v, (1 + k2 /.35) / v, (1 + k2 /.22) / v, (1 + k2 /.15) / v);
X
X	fprintf(fptr,
X		"For primary plot at fixed a = [NADH]:\n");
X	fprintf(fptr,
X		"intersection (1/b = 1/[Pyruvate], 1/V)  %10.2f%10.2f\n",
X		-k1 / k3, vint);
X	fprintf(fptr,
X		"1/V intercepts at a = (.035,.022,.015,.011) %8.2f%8.2f%8.2f%8.2f\n\n",
X		(1 + k1 /.035) / v, (1 + k1 /.022) / v, (1 + k1 /.015) / v, (1 + k1 /.011) / v);
X
X	fprintf(fptr,
X		"For secondary plot:\n");
X	fprintf(fptr,
X		"1/a = 1/[NADH] and 1/b = 1/[Pyruvate] intercepts %9.2f%10.2f\n", -1 / k1, -1 / k2);
X	fprintf(fptr,
X		"1/V intercept     \t\t\t\t%10.2f\n\n", 1 / v);
X
X	fprintf(fptr, "For lactate inhibition, at a = [NADH] = 0.035\n");
X	fprintf(fptr, "1/V values at 1/b = 1/[Pyruvate] = 0 and 5.0\n");
X	fprintf(fptr, "\t\t\t- Lactate%7.2f%10.2f\n", v1, (v1 + 5 * s1));
X	fprintf(fptr, "\t\t\t+ Lactate%7.2f%10.2f\n\n", v2, (v2 + 5 * s2));
X
X	fprintf(fptr,
X	  "R(+/-,intercept), R(+/-,slope)%10.2f%10.2f\n", v2 / v1, s2 / s1);
X
X	fprintf(fptr,
X		"\n\n\n\nValues of the kinetic constants\n");
X	fprintf(fptr, "parm(0) = V        %17.11e\n", v);
X	fprintf(fptr, "parm(1) = KmA      %17.11e\n", k1);
X	fprintf(fptr, "parm(2) = KmB      %17.11e\n", k2);
X	fprintf(fptr, "parm(3) = KmAB     %17.11e\n", k3);
X	fprintf(fptr, "parm(4) = KmQ/KmPQ %17.11e\n", k4);
X	fprintf(fptr, "parm(5) = 1/K(I,P) %17.11e\n", k5);
X
X}				/* END OF FPOINTPRINT			 */
X
X/*-
XFSPECIAL
X	DISPLAY ADDITIONAL INFORMATION DURING
X	TRACKING OF MINIMIZATION, IN SIMPFIT()
X*/
X
void
fspecial(fptr)
X	FILE           *fptr;
X{
X	register        j;
X
X	extern int      maxiter;
X	extern double   ypmin, yzero, quad_test;
X
X	if (ypmin > 0.99E38) {
X		fprintf(fptr, "y-pmin error");
X		for (j = 0; j < nvert; j++)
X			if (pmin.parm[j] < 0)
X				fprintf(fptr, " (parm(%d) < 0)", j);
X	} else if (ypmin > yzero)
X		fprintf(fptr, "y-pmin > yzero");
X
X	fprintf(fptr, "    maxiter = %d  quad_test = %7.2e\n",
X		maxiter, quad_test);
X
X	return;
X}				/* END OF FSPECIAL			 */
END_OF_FILE
if test 6480 -ne `wc -c <'./Ldh/ldhfit.c'`; then
    echo shar: \"'./Ldh/ldhfit.c'\" unpacked with wrong size!
fi
# end of './Ldh/ldhfit.c'
fi
if test -f './Ldh/ldhfit.test2' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'./Ldh/ldhfit.test2'\"
else
echo shar: Extracting \"'./Ldh/ldhfit.test2'\" \(5843 characters\)
sed "s/^X//" >'./Ldh/ldhfit.test2' <<'END_OF_FILE'
X
wednesday 1989, group 3, soaring bear and julianne ruterman
X
summary of simplex fitting results:
iteration number 398
X
simplex:
vertex = 0   function value = 1.41445213821802e-04
X   2.0725372066e-01   2.9591207538e-02   3.8790844029e-01   2.8238485628e-03
X     7.4934730527e-03   1.8932288332e-03   1.0000000000e-10
vertex = 1   function value = 1.41445215483917e-04
X   2.0725236057e-01   2.9591848835e-02   3.8790861305e-01   2.8238380121e-03
X     7.4933965668e-03   1.8931637402e-03   1.0000000000e-10
vertex = 2   function value = 1.41445215648247e-04
X   2.0725210976e-01   2.9591326173e-02   3.8789443034e-01   2.8238909666e-03
X     7.4931593266e-03   1.8934405278e-03   1.0000000000e-10
vertex = 3   function value = 1.41445212623025e-04
X   2.0725253973e-01   2.9591228961e-02   3.8791076926e-01   2.8239131657e-03
X     7.4935660242e-03   1.8929660348e-03   1.0000000000e-10
vertex = 4   function value = 1.41445215152122e-04
X   2.0725218027e-01   2.9591242637e-02   3.8791020012e-01   2.8238760792e-03
X     7.4928081537e-03   1.8934498778e-03   1.0000000000e-10
vertex = 5   function value = 1.41445213818549e-04
X   2.0725211767e-01   2.9591207862e-02   3.8790834588e-01   2.8238545636e-03
X     7.4933664786e-03   1.8935357406e-03   1.0000000000e-10
vertex = 6   function value = 1.41445211834028e-04
X   2.0724805649e-01   2.9590086968e-02   3.8789460143e-01   2.8239192601e-03
X     7.4933493000e-03   1.8932042269e-03   1.0000000000e-10
X
centroid:
function value = 1.41445212067140e-04
X   2.0725186931e-01   2.9591164139e-02   3.8790505720e-01   2.8238772300e-03
X     7.4933027003e-03   1.8932841402e-03   1.0000000000e-10
mean=1.41445214054527e-04 rms=1.35633285798876e-12 test=9.58910393013292e-09
root mean square weighted error of best fit to data = 2.53561192035328e-03
X
X
wednesday 1989, group 3, soaring bear and julianne ruterman
X
iteration number 398
X
X        yobs   ycalc   del-y  weight       a         b         p
X   1   0.024   0.026  -0.002   1.000    0.01100    0.15000    0.00000
X   2   0.025   0.030  -0.005   0.000    0.01500    0.15000    0.00000
X   3   0.036   0.036   0.000   1.000    0.02200    0.15000    0.00000
X   4   0.040   0.042  -0.002   1.000    0.03500    0.15000    0.00000
X   5   0.034   0.031   0.003   1.000    0.01100    0.22000    0.00000
X   6   0.036   0.037  -0.001   1.000    0.01500    0.22000    0.00000
X   7   0.043   0.044  -0.001   1.000    0.02200    0.22000    0.00000
X   8   0.052   0.052  -0.000   1.000    0.03500    0.22000    0.00000
X   9   0.039   0.037   0.002   1.000    0.01100    0.35000    0.00000
X  10   0.045   0.045   0.000   1.000    0.01500    0.35000    0.00000
X  11   0.054   0.054  -0.000   1.000    0.02200    0.35000    0.00000
X  12   0.067   0.065   0.002   1.000    0.03500    0.35000    0.00000
X  13   0.046   0.045   0.001   1.000    0.01100    0.70000    0.00000
X  14   0.056   0.055   0.001   1.000    0.01500    0.70000    0.00000
X  15   0.065   0.067  -0.002   1.000    0.02200    0.70000    0.00000
X  16   0.087   0.082   0.005   1.000    0.03500    0.70000    0.00000
X  17   0.020   0.026  -0.006   0.000    0.01100    0.15000    0.00000
X  18   0.043   0.042   0.001   1.000    0.03500    0.15000    0.00000
X  19   0.043   0.045  -0.002   1.000    0.01100    0.70000    0.00000
X  20   0.078   0.082  -0.004   1.000    0.03500    0.70000    0.00000
X  21   0.022   0.019   0.003   1.000    0.03500    0.15000  150.00000
X  22   0.020   0.024  -0.004   1.000    0.03500    0.22000  150.00000
X  23   0.030   0.032  -0.002   1.000    0.03500    0.35000  150.00000
X  24   0.041   0.044  -0.003   1.000    0.03500    0.70000  150.00000
X  25   0.021   0.019   0.002   1.000    0.03500    0.15000  150.00000
X  26   0.048   0.044   0.004   1.000    0.03500    0.70000  150.00000
X  27   0.052   0.042   0.010   0.000    0.03500    0.15000    0.00000
X  28   0.035   0.045  -0.010   0.000    0.01100    0.70000    0.00000
X
wednesday 1989, group 3, soaring bear and julianne ruterman
X
iteration number 398
X
XFor primary plot at fixed b = [Pyruvate]:
intersection (1/a = 1/[NADH], 1/V)         -137.37    -14.79
X1/V intercepts at b = (.7,.35,.22,.15)          7.50   10.17   13.33   17.30
X
XFor primary plot at fixed a = [NADH]:
intersection (1/b = 1/[Pyruvate], 1/V)      -10.48    -14.79
X1/V intercepts at a = (.035,.022,.015,.011)     8.90   11.31   14.34   17.80
X
XFor secondary plot:
X1/a = 1/[NADH] and 1/b = 1/[Pyruvate] intercepts    -33.79     -2.58
X1/V intercept     				      4.83
X
XFor lactate inhibition, at a = [NADH] = 0.035
X1/V values at 1/b = 1/[Pyruvate] = 0 and 5.0
X			- Lactate   8.90     20.21
X			+ Lactate  14.33     43.98
X
R(+/-,intercept), R(+/-,slope)      1.61      2.62
X
X
X
X
Values of the kinetic constants
parm(0) = V        2.07251869308e-01
parm(1) = KmA      2.95911641391e-02
parm(2) = KmB      3.87905057195e-01
parm(3) = KmAB     2.82387723003e-03
parm(4) = KmQ/KmPQ 7.49330270035e-03
parm(5) = 1/K(I,P) 1.89328414020e-03
X
wednesday 1989, group 3, soaring bear and julianne ruterman
X
summary of results of quadratic fit
iteration number 398
X
mean=1.41445214054527e-04 rms=1.35633285798876e-12 test=9.58910393013292e-09
X
mse    = 6.42932781063765e-06   rms weighted error = 2.53561192035328e-03
X
yzero  = 1.41445211834028e-04
ymin   = 1.41445211834025e-04
y-pmin = 1.41445211834023e-04
X
free parm    q                centroid         pmin             std_dev
X  0   0 3.81281595219e-06 2.07248056492e-01 2.07248033021e-01 3.64881495871e-02
X  1   1 1.07717096933e-06 2.95900869681e-02 2.95900810279e-02 9.25205078765e-03
X  2   2 1.05046526666e-05 3.87894601425e-01 3.87894518855e-01 1.33650006676e-01
X  3   3 4.20300566109e-08 2.82391926008e-03 2.82391984396e-03 1.34937978730e-03
X  4   4 1.62291729170e-07 7.49334929995e-03 7.49334814879e-03 3.00573015779e-03
X  5   5 1.59535815746e-07 1.89320422685e-03 1.89320534244e-03 3.60112413271e-03
END_OF_FILE
echo shar: 4 control characters may be missing from \"'./Ldh/ldhfit.test2'\"
if test 5843 -ne `wc -c <'./Ldh/ldhfit.test2'`; then
    echo shar: \"'./Ldh/ldhfit.test2'\" unpacked with wrong size!
fi
# end of './Ldh/ldhfit.test2'
fi
if test -f './Ldh/ldhfit.testx' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'./Ldh/ldhfit.testx'\"
else
echo shar: Extracting \"'./Ldh/ldhfit.testx'\" \(5844 characters\)
sed "s/^X//" >'./Ldh/ldhfit.testx' <<'END_OF_FILE'
X
wednesday 1989, group 3, soaring bear and julianne ruterman
X
summary of simplex fitting results:
iteration number 575
X
simplex:
vertex = 0   function value = 1.47271911471040e-04
X   1.9442204905e-01   2.6579588663e-02   3.3806990045e-01   3.1476553895e-03
X     4.9294861335e-03   6.1847852943e-03   1.0000000000e-10
vertex = 1   function value = 1.47271914515101e-04
X   1.9443612214e-01   2.6582646308e-02   3.3812758075e-01   3.1473165174e-03
X     4.9295302493e-03   6.1843290316e-03   1.0000000000e-10
vertex = 2   function value = 1.47271911088589e-04
X   1.9444389621e-01   2.6585087417e-02   3.3814251554e-01   3.1471683819e-03
X     4.9299489828e-03   6.1841740179e-03   1.0000000000e-10
vertex = 3   function value = 1.47271909992871e-04
X   1.9442863502e-01   2.6582131459e-02   3.3808103985e-01   3.1475257775e-03
X     4.9299779179e-03   6.1846551559e-03   1.0000000000e-10
vertex = 4   function value = 1.47271911133816e-04
X   1.9443760399e-01   2.6583623415e-02   3.3811803272e-01   3.1473793473e-03
X     4.9295834071e-03   6.1843859908e-03   1.0000000000e-10
vertex = 5   function value = 1.47271912275166e-04
X   1.9443427188e-01   2.6582469940e-02   3.3810637177e-01   3.1473653002e-03
X     4.9299172806e-03   6.1844658544e-03   1.0000000000e-10
vertex = 6   function value = 1.47271911675280e-04
X   1.9443186956e-01   2.6581959159e-02   3.3809506379e-01   3.1474678709e-03
X     4.9297299224e-03   6.1845627949e-03   1.0000000000e-10
X
centroid:
function value = 1.47271909675299e-04
X   1.9443349255e-01   2.6582500909e-02   3.3810578641e-01   3.1474112264e-03
X     4.9297391277e-03   6.1844797343e-03   1.0000000000e-10
mean=1.47271911735980e-04 rms=1.30429285355509e-12 test=8.85635854237663e-09
root mean square weighted error of best fit to data = 2.58731090651060e-03
X
X
wednesday 1989, group 3, soaring bear and julianne ruterman
X
iteration number 575
X
X        yobs   ycalc   del-y  weight       a         b         p
X   1   0.024   0.026  -0.002   1.000    0.01100    0.15000    0.00000
X   2   0.025   0.030  -0.005   0.000    0.01500    0.15000    0.00000
X   3   0.036   0.036   0.000   1.000    0.02200    0.15000    0.00000
X   4   0.040   0.042  -0.002   1.000    0.03500    0.15000    0.00000
X   5   0.034   0.031   0.003   1.000    0.01100    0.22000    0.00000
X   6   0.036   0.037  -0.001   1.000    0.01500    0.22000    0.00000
X   7   0.043   0.044  -0.001   1.000    0.02200    0.22000    0.00000
X   8   0.052   0.052   0.000   1.000    0.03500    0.22000    0.00000
X   9   0.039   0.037   0.002   1.000    0.01100    0.35000    0.00000
X  10   0.045   0.045   0.000   1.000    0.01500    0.35000    0.00000
X  11   0.054   0.054   0.000   1.000    0.02200    0.35000    0.00000
X  12   0.067   0.065   0.002   1.000    0.03500    0.35000    0.00000
X  13   0.046   0.045   0.001   1.000    0.01100    0.70000    0.00000
X  14   0.056   0.055   0.001   1.000    0.01500    0.70000    0.00000
X  15   0.065   0.067  -0.002   1.000    0.02200    0.70000    0.00000
X  16   0.087   0.082   0.005   1.000    0.03500    0.70000    0.00000
X  17   0.020   0.026  -0.006   0.000    0.01100    0.15000    0.00000
X  18   0.043   0.042   0.001   1.000    0.03500    0.15000    0.00000
X  19   0.043   0.045  -0.002   1.000    0.01100    0.70000    0.00000
X  20   0.078   0.082  -0.004   1.000    0.03500    0.70000    0.00000
X  21   0.022   0.018   0.004   1.000    0.03500    0.15000  150.00000
X  22   0.020   0.023  -0.003   1.000    0.03500    0.22000  150.00000
X  23   0.030   0.031  -0.001   1.000    0.03500    0.35000  150.00000
X  24   0.041   0.045  -0.004   1.000    0.03500    0.70000  150.00000
X  25   0.021   0.018   0.003   1.000    0.03500    0.15000  150.00000
X  26   0.048   0.045   0.003   1.000    0.03500    0.70000  150.00000
X  27   0.052   0.042   0.010   0.000    0.03500    0.15000    0.00000
X  28   0.035   0.045  -0.010   0.000    0.01100    0.70000    0.00000
X
wednesday 1989, group 3, soaring bear and julianne ruterman
X
iteration number 575
X
XFor primary plot at fixed b = [Pyruvate]:
intersection (1/a = 1/[NADH], 1/V)         -107.42     -9.54
X1/V intercepts at b = (.7,.35,.22,.15)          7.63   10.11   13.05   16.74
X
XFor primary plot at fixed a = [NADH]:
intersection (1/b = 1/[Pyruvate], 1/V)       -8.45     -9.54
X1/V intercepts at a = (.035,.022,.015,.011)     9.05   11.36   14.26   17.57
X
XFor secondary plot:
X1/a = 1/[NADH] and 1/b = 1/[Pyruvate] intercepts    -37.62     -2.96
X1/V intercept     				      5.14
X
XFor lactate inhibition, at a = [NADH] = 0.035
X1/V values at 1/b = 1/[Pyruvate] = 0 and 5.0
X			- Lactate   9.05     20.06
X			+ Lactate  12.85     46.03
X
R(+/-,intercept), R(+/-,slope)      1.42      3.01
X
X
X
X
Values of the kinetic constants
parm(0) = V        1.94433492550e-01
parm(1) = KmA      2.65825009088e-02
parm(2) = KmB      3.38105786409e-01
parm(3) = KmAB     3.14741122638e-03
parm(4) = KmQ/KmPQ 4.92973912766e-03
parm(5) = 1/K(I,P) 6.18447973425e-03
X
wednesday 1989, group 3, soaring bear and julianne ruterman
X
summary of results of quadratic fit
iteration number 575
X
mean=1.47271911735980e-04 rms=1.30429285355509e-12 test=8.85635854237663e-09
X
mse    = 6.69417771251357e-06   rms weighted error = 2.58731090372100e-03
X
yzero  = 1.47271909675299e-04
ymin   = 1.33874704299415e-04
y-pmin = 1.00000000000000e+38
X
free parm    q                centroid         pmin             std_dev
X  0   0 5.12114696899e-06 1.94433492550e-01 2.27888774979e-01 3.93582166815e-02
X  1   1 1.10126099130e-06 2.65825009088e-02 3.46008854645e-02 9.89846048503e-03
X  2   2 2.03871833351e-05 3.38105786409e-01 4.69326425997e-01 1.47356847326e-01
X  3   3 1.18673914700e-07 3.14741122638e-03 2.20165827887e-03 1.43084268157e-03
X  4   4 1.79085254152e-07 4.92973912766e-03 1.05284044319e-02 4.01014694978e-03
X  5   5 1.61154953522e-07 6.18447973425e-03 -6.36491616416e-03 8.91584702851e-03
END_OF_FILE
echo shar: 4 control characters may be missing from \"'./Ldh/ldhfit.testx'\"
if test 5844 -ne `wc -c <'./Ldh/ldhfit.testx'`; then
    echo shar: \"'./Ldh/ldhfit.testx'\" unpacked with wrong size!
fi
# end of './Ldh/ldhfit.testx'
fi
if test -f './Lib/simpdev.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'./Lib/simpdev.c'\"
else
echo shar: Extracting \"'./Lib/simpdev.c'\" \(7099 characters\)
sed "s/^X//" >'./Lib/simpdev.c' <<'END_OF_FILE'
X/* SIMPDEV.C */
X/*-
quadratic fit for standard deviations	= simpdev()
X  
J.A. Rupley, Tucson, Arizona
rupley!local@megaron.arizona.edu
X*/
X
X#define SIMPDEV
X
X#include "simpdefs.h"
X
X/*-
SIMPDEV
X	QUADRATIC FIT TO FUNCTION SURFACE FOR ESTIMATION OF:
X		VARIANCE-COVARIANCE MATRIX 
X		STANDARD DEVIATIONS OF PARAMETERS
X*/
X
int
simpdev(fptr)
X	FILE           *fptr;
X{
X	register int    i, j, k, l;
X	int             xfree, free_cnt;
X	int             err_count;
X
X	double          dtemp;
X	double          yminusij, yplusij;
X
X	double          tmparray[NPARM];
X
X	struct pstruct  ptemp;
X
X	extern double   sqrt();
X
X	extern          func();
X	extern void     fpprint();
X	extern void     pcopy();
X	extern void     fqprint();
X	extern void     fmatprint();
X
X	extern void     qsort();
X	extern          pvalcomp();
X
X	/* set pcent.val */
X	if (func(&pcent) == ERROR)
X		return (ERROR);
X
X	/*
X	 * ascending sort of pointers p_p to struct array p 
X	 */
X	qsort((char *) p_p, (unsigned) nvert, sizeof(*p_p), pvalcomp);
X
X	/*
X	 * if lowest vertex < centroid, then replace centroid by lowest
X	 * vertex 
X	 */
X	if (p_p[0]->val < pcent.val) {
X		pcopy(&pcent, p_p[0]);
X		fprintf(fptr, "\n\nlowest vertex replaces centroid");
X	}
X	yzero = pcent.val;
X	fprintf(fptr,
X		"\n\nlowest function value = yzero = %20.14e\n\n", yzero);
X	fpprint(fptr, &pcent);
X	fprintf(fptr, "\n");
X
X	/*
X	 * calculate q value = avg devn of a free parameter from the centroid
X	 * value; 
X	 *
X	 * store the q value in structure q : q.q[free_cnt] = q value; 
X	 *
X	 * also store map of free parm to parm array in q.parmndx[free_cnt] =
X	 * index of parm in p[nvert].parm[nparm]; 
X	 *
X	 * set nfree and nvert 
X	 */
X	free_cnt = 0;
X	for (i = 0; i < nparm; i++) {
X		dtemp = 0;
X		for (j = 0; j < nvert; j++)
X			dtemp = dtemp + ABS(p[j].parm[i] - pcent.parm[i]);
X		dtemp = dtemp / nvert;
X		if (ABS(dtemp / pcent.parm[i]) < 1.0e-16) {
X			fprintf(fptr, "parameter %d is fixed\n", i);
X			continue;
X		} else {
X			q.q[free_cnt] = dtemp;
X			q.parmndx[free_cnt] = i;
X			free_cnt++;
X		}
X	}
X	nfree = free_cnt;
X	if (nvert != (nfree + 1)) {
X		fprintf(fptr, "\nerror in count of free parameters\n");
X		return (ERROR);
X	}
X	fprintf(fptr,
X		"\nq values for the %d free parameters out of %d total:\n",
X		nfree, nparm);
X	fqprint(fptr, q.q);
X
X	/*
X	 * check and if necessary adjust q values for each free parameter, to
X	 * be sure that the function values are OK for the centroid parameter
X	 * values  (+  &  -)  q; 
X	 *
X	 * store function value for parameter value (+  &  -)  q   in  q.yplus 
X	 * and  q.yminus 
X	 */
X	for (i = 0; i < nfree; i++) {
X		k = q.parmndx[i];
X		pcopy(&ptemp, &pcent);
X		fprintf(fptr,
X			"\nchecking q value %d, for parameter %d: ", i, k);
X		while (TRUE) {
X			fprintf(fptr, "*");
X
X			while (TRUE) {
X				ptemp.parm[k] = pcent.parm[k] - q.q[i];
X				if (func(&ptemp) == ERROR)
X					q.q[i] = q.q[i] / 2;
X				else
X					break;
X			}
X			q.yminus[i] = ptemp.val;
X
X			dtemp = q.q[i];
X			while (TRUE) {
X				ptemp.parm[k] = pcent.parm[k] + dtemp;
X				if (func(&ptemp) == ERROR)
X					dtemp = dtemp / 2;
X				else
X					break;
X			}
X			q.yplus[i] = ptemp.val;
X
X			if (dtemp == q.q[i])
X				break;
X			else
X				q.q[i] = dtemp;
X		}
X	}
X	fprintf(fptr, "\n\nadjusted q values:\n");
X	fqprint(fptr, q.q);
X	fprintf(fptr, "\nyplus values:\n");
X	fqprint(fptr, q.yplus);
X	fprintf(fptr, "\nyminus values:\n");
X	fqprint(fptr, q.yminus);
X
X	/*
X	 * calculate  <a>  vector; store in q.a; 
X	 *
X	 * calculate  <B>  matrix diagonal elements; 
X	 *
X	 * store in  qmat  and  q.bdiag  
X	 */
X	for (i = 0; i < nfree; i++) {
X		q.a[i] = 0.25 * (q.yplus[i] - q.yminus[i]);
X		qmat[i][i] = q.bdiag[i] = 0.5 * (q.yplus[i] + q.yminus[i]
X						 - 2 * yzero);
X	}
X	fprintf(fptr, "\n<a> vector:\n");
X	fqprint(fptr, q.a);
X	fprintf(fptr,
X		"\n<B> matrix diagonal:\n");
X	fqprint(fptr, q.bdiag);
X
X	/*
X	 * calculate <B>  matrix off-diagonal elements; 
X	 *
X	 * keep track of any function errors; 
X	 *
X	 * store results in  qmat  
X	 */
X	err_count = 0;
X	for (i = 1; i < nfree; i++) {
X		k = q.parmndx[i];
X		fprintf(fptr,
X			"\ncalculating off-diag Bij for row %d: ", i);
X		for (j = 0; j < i; j++) {
X			fprintf(fptr, "*");
X			l = q.parmndx[j];
X			pcopy(&ptemp, &pcent);
X
X			ptemp.parm[k] = pcent.parm[k] + q.q[i];
X			ptemp.parm[l] = pcent.parm[l] + q.q[j];
X			if (func(&ptemp) == ERROR)
X				++err_count;
X			yplusij = ptemp.val;
X
X			ptemp.parm[k] = pcent.parm[k] - q.q[i];
X			ptemp.parm[l] = pcent.parm[l] - q.q[j];
X			if (func(&ptemp) == ERROR)
X				++err_count;
X			yminusij = ptemp.val;
X
X			qmat[j][i] = qmat[i][j] = 0.25 * (yplusij + yminusij
X				      + 2 * yzero - q.yplus[i] - q.yminus[i]
X						- q.yplus[j] - q.yminus[j]);
X		}
X	}
X	if (err_count > 0) {
X		fprintf(fptr, "\n\n%d function errors in <B> matrix calculation\n",
X			err_count);
X		return (ERROR);
X	}
X	fprintf(fptr, "\n\n<B> matrix:\n");
X	fmatprint(fptr, qmat);
X
X	/*
X	 * invert <B>  matrix  
X	 */
X	xfree = nfree - 1;
X	for (l = 0; l < nfree; l++) {
X		tmparray[xfree] = 1 / qmat[0][0];
X
X		for (i = 0; i < xfree; i++)
X			tmparray[i] = tmparray[xfree] * qmat[0][i + 1];
X
X		for (i = 0; i < xfree; i++) {
X			qmat[i][xfree] = -tmparray[xfree] * qmat[i + 1][0];
X			for (j = 0; j < xfree; j++)
X				qmat[i][j] = qmat[i + 1][j + 1]
X					- tmparray[j] * qmat[i + 1][0];
X		}
X
X		for (i = 0; i < nfree; i++)
X			qmat[xfree][i] = tmparray[i];
X	}
X	fprintf(fptr, "\n<B> matrix inverse:\n");
X	fmatprint(fptr, qmat);
X
X
X	/* store inv B matrix diagonal in q.inv_bdiag  */
X	/* calculate: ymin = yzero - sumij(ai * invBij * aj)  */
X	/* calculate: pmin(k) = centroid(k) - sumj(qi * invBij * aj)  */
X	/* where k = parmndx[i] if parm[k] free and  */
X	/* pmin = centroid if parm[k] fixed  */
X	ymin = yzero;
X	pcopy(&pmin, &pcent);
X	for (i = 0; i < nfree; i++) {
X		q.inv_bdiag[i] = qmat[i][i];
X		k = q.parmndx[i];
X		for (j = 0; j < nfree; j++) {
X			ymin = ymin - q.a[i] * qmat[i][j] * q.a[j];
X			pmin.parm[k] = pmin.parm[k]
X				- q.q[i] * qmat[i][j] * q.a[j];
X		}
X	}
X	if (func(&pmin) == ERROR)
X		fprintf(fptr, "\nerror in y-pmin\n");
X	ypmin = pmin.val;
X
X	/* calculate  mse = (func val)/degrees freedom & rms error */
X	/* calculate  variance-covariance matrix */
X	/* vcij = qi * invBij * qj * mse */
X	/* calculate  standard deviations */
X	mse = pcent.val / (ndata - nfree);
X	rms_data = sqrt(mse);
X	for (i = 0; i < nfree; i++) {
X		for (j = i; j < nfree; j++) {
X			qmat[i][j] = qmat[j][i]
X				= q.q[i] * qmat[i][j] * q.q[j] * mse;
X		}
X		q.std_dev[i] = qmat[i][i] < 0 ? -1 : sqrt(qmat[i][i]);
X	}
X	fprintf(fptr,
X		"\nvariance-covariance matrix:\n");
X	fmatprint(fptr, qmat);
X
X	/*
X	 * replace centroid with pmin, if y-pmin  <  y-centroid; 
X	 *
X	 * reconstruct simplex, based on q values and centroid, in preparation
X	 * for more fitting; 
X	 *
X	 * nfree vertices are based on nfree q values; 
X	 *
X	 * the remaining vertex is set at the centroid (or pmin if it is lower) 
X	 */
X	fprintf(fptr, "\n\nCalculating for reconstructed simplex...\n\n");
X	if (pmin.val < pcent.val)
X		pcopy(&p[nfree], &pmin);
X	else
X		pcopy(&p[nfree], &pcent);
X	for (i = 0; i < nfree; i++) {
X		pcopy(&p[i], &pcent);
X		k = q.parmndx[i];
X		p[i].parm[k] = p[i].parm[k] + q.q[i];
X		func(&p[i]);
X	}
X
X	return (OK);
X}				/* END OF SIMPDEV      			 */
END_OF_FILE
if test 7099 -ne `wc -c <'./Lib/simpdev.c'`; then
    echo shar: \"'./Lib/simpdev.c'\" unpacked with wrong size!
fi
# end of './Lib/simpdev.c'
fi
if test -f './Lib/simpinput.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'./Lib/simpinput.c'\"
else
echo shar: Extracting \"'./Lib/simpinput.c'\" \(6299 characters\)
sed "s/^X//" >'./Lib/simpinput.c' <<'END_OF_FILE'
X/* SIMPINPUT.C */
X/*-
routines for input of data and control values for simplex minimization:
X  
the routine is (essentially) independent of the function and data to be fit
X	(coded in XXXXFIT), and it generally need not be altered when 
X	XXXXFIT is modified.
X  
The code is particularly clumsy, and may reflect porting from Fortran to
CP/M Basic, to CP/M C, to UNIX -- in its travels with me over the last
X15+ years.
X  
J.A. Rupley, Tucson, Arizona
rupley!local@megaron.arizona.edu
X*/
X
X#define SIMPINPUT
X
X#include "simpdefs.h"
X
X#define MANYITER	10000
X
X/*-
READ_DATA
X	ENTRY OF TITLE, CONTROL VARIABLES, STARTING SIMPLEX, AND DATA
X		FROM DISK FILE
X	MANIPULATION OF DATA PRIOR TO FITTING SHOULD BE DONE HERE (OR IN
X		MAIN())
X	THE DISK DATA FILE IS FREE-FORM (IE, WITHOUT FIELD WIDTHS), 
X		BUT THE SEQUENCE OF ENTRIES MUST BE EXACTLY AS BELOW
X	THE MNEMONIC IDENTIFIERS MUST BE IN THE DATA FILE (THEY ARE
X		DISCARDED IN THE READ, BUT ARE ASSUMED TO BE PRESENT)
X	THE IDENTIFIERS CANNOT CONTAIN WHITE SPACE
X	THE ONE-LINE & < 80 CHAR TITLE CANNOT CONTAIN CONTROL CHARACTERS
X*/
X
int
read_data(fp_out, fptr)
XFILE           *fp_out;
XFILE           *fptr;
X{
X	register int    i, j;
X	char            dummy[200];
X
X	extern char    *str_in();
X	extern char    *num_in();
X	extern void     fdatprint();
X	extern void     fpprint();
X	extern void     fsprint();
X	extern void     use_mess();
X	extern          func();
X
X	extern double   atof();
X	extern void     enditall();
X
X	/*
X	 * read and print title 
X	 */
X	for (i = 0; i < 79; i++) {
X		if (iscntrl(title[i] = getc(fptr)))
X			break;
X	}
X	title[i] = '\0';
X	fprintf(fp_out, "\n%-s\n\n", title);
X
X	/*
X	 * read and print nvert, nparm, ndata, ndatval 
X	 */
X	if (str_in(fptr, dummy) != NULL)
X		enditall();
X	fprintf(fp_out, "nvert = %d\n",
X		nvert = atoi(num_in(fptr, dummy)));
X	if ((nvert <= 0) || (nvert > (NPARM + 1)))
X		enditall();
X	if (str_in(fptr, dummy) != NULL)
X		enditall();
X	fprintf(fp_out, "nparm = %d\n",
X		nparm = atoi(num_in(fptr, dummy)));
X	if ((nparm <= 0) || (nparm > NPARM))
X		enditall();
X	if (str_in(fptr, dummy) != NULL)
X		enditall();
X	fprintf(fp_out, "ndata = %d\n",
X		ndata = atoi(num_in(fptr, dummy)));
X	if ((ndata <= 0) || (ndata > NDATA))
X		enditall();
X	if (str_in(fptr, dummy) != NULL)
X		enditall();
X	fprintf(fp_out, "ndatval = %d\n",
X		ndatval = atoi(num_in(fptr, dummy)));
X	if ((ndatval <= 0) || (ndatval > NDATVAL))
X		enditall();
X	nfree = nvert - 1;
X
X	/*
X	 * read and print iter, maxiter, exit_test, prt_cycle, quad_test 
X	 */
X	if (str_in(fptr, dummy) != NULL)
X		enditall();
X	fprintf(fp_out, "iter = %d\n",
X		iter = atoi(num_in(fptr, dummy)));
X	if ((iter < 0) || (iter > MANYITER))
X		enditall();
X	if (str_in(fptr, dummy) != NULL)
X		enditall();
X	fprintf(fp_out, "maxquad_skip = %d\n",
X		maxquad_skip = atoi(num_in(fptr, dummy)));
X	if ((maxquad_skip < 0) || (maxquad_skip > MANYITER))
X		enditall();
X	if (str_in(fptr, dummy) != NULL)
X		enditall();
X	fprintf(fp_out, "exit_test = %20.14e\n",
X		exit_test = atof(num_in(fptr, dummy)));
X	if ((exit_test <= 0))
X		enditall();
X	if (str_in(fptr, dummy) != NULL)
X		enditall();
X	fprintf(fp_out, "prt_cycle = %d\n",
X		prt_cycle = atoi(num_in(fptr, dummy)));
X	if ((prt_cycle < 0) || (prt_cycle > MANYITER))
X		enditall();
X	if (str_in(fptr, dummy) != NULL)
X		enditall();
X	fprintf(fp_out, "quad_test = %20.14e\n",
X		quad_test = atof(num_in(fptr, dummy)));
X	if ((quad_test < 0))
X		enditall();
X
X	/*
X	 * read and print simplex 
X	 */
X	if (str_in(fptr, dummy) != NULL)
X		enditall();
X	fprintf(fp_out, "\n\n%-79s\n", dummy);
X	for (j = 0; j < nvert; j++) {
X		for (i = 0; i < nparm; i++) {
X			p[j].parm[i] = atof(num_in(fptr, dummy));
X			fprintf(fp_out, "vert[%d].parm[%d] = %20.14e\n",
X				j, i, p[j].parm[i]);
X		}
X	}
X
X	/*
X	 * read and print bounds, if present 
X	 */
X	if (str_in(fptr, dummy) != NULL)
X		enditall();
X	if (strncmp(dummy, "parm-bounds", 11) == 0) {
X		fprintf(fp_out, "\n\n%-79s\n", dummy);
X		for (j = 0; j < 2; j++) {
X			for (i = 0; i < nparm; i++) {
X				bounds[j][i] = atof(num_in(fptr, dummy));
X				fprintf(fp_out, "bounds[%d][%d] = %20.14e\n",
X					j, i, bounds[j][i]);
X			}
X		}
X		if (str_in(fptr, dummy) != NULL)
X			enditall();
X	}
X
X	/*
X	 * read and print data array 
X	 */
X	fprintf(fp_out, "\n\n%-79s\n", dummy);
X	for (j = 0; j < ndata; j++) {
X		for (i = 0; i < ndatval; i++)
X			data[j].datval[i] = atof(num_in(fptr, dummy));
X	}
X	maxiter = 0;
X	fdatprint(fp_out);
X
X	/*
X	 * calculate function values and print simplex 
X	 */
X	fprintf(fp_out, "\n\ncalculating function values: ");
X	for (j = 0; j < nvert; j++) {
X		func(&p[j]);
X		fprintf(fp_out, "%d ", j);
X	}
X	fsprint(fp_out, "\n\nsimplex:\n");
X	return (OK);
X}				/* END OF READ_DATA			 */
X
void
use_mess()
X{
X	puts("\nUsage:");
X	puts("xxxxfit   [-s a,c,l,n] [-d a,c,l,n] [[-i] inputfile [[-o] diskfile]");
X	puts("   -s and -d control output to terminal and diskfile;");
X	puts("           a = ALL possible output;              c = ouput each CYCLE");
X	puts("           l = output on LAST cycle only;        n = NO output;");
X	puts("   output to terminal defaults to ALL possible output to stdout;");
X	puts("   inputfile and diskfile default to stdin and /dev/null;");
X	puts("   the input file has the following structure:");
X	puts("     one-line title, with no tabs or ctrl characters;");
X	puts("     lines following give control variables, the starting simplex,");
X	puts("              and the data array;");
X	puts("     the order of entry is fixed by the order in <read_data()>;");
X	puts("              see template file for structure;");
X	puts("     the one-word descriptors must be present in the data file;");
X	puts("     the data format is free-form (no set field widths);");
X	puts("     comments at the end of the file are not read by the program");
X}				/* END OF USE_MESS			 */
X
char           *
str_in(fptr, dummy)
X	char           *dummy;
X	FILE           *fptr;
X{
X	register int    i;
X
X	while (isspace(dummy[0] = getc(fptr)));
X	for (i = 1; !isspace(dummy[i] = getc(fptr)); i++);
X	dummy[i] = '\0';
X	if (isalpha(dummy[0]))
X		return (NULL);
X	else
X		return (&dummy[0]);
X}				/* END OF *STR_IN */
X
char           *
num_in(fptr, dummy)
X	char           *dummy;
X	FILE           *fptr;
X{
X	int             i;
X
X	while (isspace(dummy[0] = getc(fptr)));
X	for (i = 1; !isspace(dummy[i] = getc(fptr)); i++);
X	dummy[i] = '\0';
X	return (&dummy[0]);
X}				/* END OF *NUM_IN */
END_OF_FILE
if test 6299 -ne `wc -c <'./Lib/simpinput.c'`; then
    echo shar: \"'./Lib/simpinput.c'\" unpacked with wrong size!
fi
# end of './Lib/simpinput.c'
fi
if test -f './Lib/simpmain.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'./Lib/simpmain.c'\"
else
echo shar: Extracting \"'./Lib/simpmain.c'\" \(6789 characters\)
sed "s/^X//" >'./Lib/simpmain.c' <<'END_OF_FILE'
X/* SIMPMAIN.C */
X/*-
control of input, output & simplex fitting 	= main()
X  
J.A. Rupley, Tucson, Arizona
rupley!local@megaron.arizona.edu
X*/
X
X#define SIMPMAIN
X
X#include "simpdefs.h"
X
X/*-
MAIN
X	MAIN PROGRAM FOR CONTROL OF:
X	SETUP FOR INPUT OF DATA FROM FILE GIVEN AS COMMAND LINE OPTION
X	SETUP FOR WRITE OF OUTPUT TO FILE GIVEN AS COMMAND LINE OPTION
X	SIMPLEX FITTING
X	QUADRATIC FIT FOR EXTRACTION OF STANDARD DEVIATIONS
X	OUTPUT TO CONSOLE AND TO FILE, ACCORDING TO COMMAND LINE OPTIONS
X*/
X
X/*-
one must initialize the following, by a call to <read_data()>:
double exit_test, quad_test
int prt_cycle, maxquad_skip
int iter, maxiter, nparm, nvert, nfree, ndatval, ndata
char title[80]
struct pstruct p[nvert] = the starting simplex
struct dat data[ndata]	= the data array, used in <func()> and <fdatprint()>
XFILE *fp_disk = optional output file
X  
on return from <read_data()>:
zero nquad_skip 
set quad_cycle = quad_test for use if quad_test >1
X  
in loop calling <simpfit()> and <simpdev()>:
reset maxiter to iter+prt_cycle
test and reset as appropriate nquad_skip and quad_test
as appropriate execute options altering flow or test values
X  
on return from <simpfit()>:
the structure <p[nvert]> has the current simplex and <pcent> the centroid,
the variables mean_func, rms_func, test, and rms_data contain the mnemonically 
indicated information.
X  
on return from <simpdev()>:
the array <qmat[nfree][nfree]> contains the variance-covariance matrix, 
the elements of structures <q> and <pmin> and variables yzero, ymin, ypmin,
and mse contain the mnemonically indicated information.
X*/
X
X/* mnemonics for output to terminal or file */
X#define ALL	3	/* maximum output - track each iteration */
X#define CYCLE	2	/* output summary values on maxiter/quad_test cycle */
X#define LAST	1	/* output summary values on last (exit) cycle only */
X#define NONE	0	/* all output to /dev/null */
X
main(argc, argv)
X	int             argc;
X	char          **argv;
X{
X	int             c;
X	int             nquad_skip, quad_cycle;
X	int             diskmode, screenmode;
X
X	FILE           *fp_input;
X	FILE           *fp_disk;
X	FILE           *fp_screen;
X	FILE           *fp_null;
X
X	extern void     use_mess();
X	extern          read_data();
X	extern          simpfit();
X	extern          simpdev();
X	extern void     ffitprint();
X	extern void     fdatprint();
X	extern void     fquadprint();
X	extern void     enditall();
X
X	extern void     exit();
X	extern double   atof();
X	extern FILE    *fopen();
X
X	extern char    *optarg;
X	extern int      optind, opterr;
X	extern int      getopt();
X
X	fp_input = stdin;
X	fp_disk = NULL;
X	fp_screen = stdout;
X	diskmode = NONE;
X	screenmode = ALL;
X
X	while ((c = getopt(argc, argv, "zi:o:d:s:")) != EOF) {
X		switch (c) {
X		case 'i':
X			if ((fp_input = fopen(optarg, "r")) == NULL) {
X				printf("sorry, cannot open input file %s\n",
X				       optarg);
X				use_mess();
X				exit(1);
X			}
X			break;
X		case 'o':
X			if ((fp_disk = fopen(optarg, "w")) == NULL) {
X				printf("sorry, cannot open output file %s\n",
X				       optarg);
X				use_mess();
X				exit(1);
X			}
X			if (diskmode == NONE)
X				diskmode = CYCLE;
X			break;
X		case 'd':
X			switch (*optarg) {
X			case 'a':
X			case 'c':
X				diskmode = CYCLE;
X				break;
X			case 'l':
X				diskmode = LAST;
X				break;
X			case 'n':
X				diskmode = NONE;
X				break;
X			default:
X				printf("bad option\n");
X				use_mess();
X				exit(1);
X			}
X			break;
X		case 's':
X			switch (*optarg) {
X			case 'a':
X				screenmode = ALL;
X				break;
X			case 'c':
X				screenmode = CYCLE;
X				break;
X			case 'l':
X				screenmode = LAST;
X				break;
X			case 'n':
X				screenmode = NONE;
X				break;
X			default:
X				printf("bad option\n");
X				use_mess();
X				exit(1);
X			}
X			break;
X		case '?':
X		case 'z':
X		default:
X			use_mess();
X			exit(1);
X		}
X	}
X
X	if ((optind < argc) && (fp_input == stdin)) {
X		if ((fp_input = fopen(argv[optind], "r")) == NULL) {
X			printf("sorry, cannot open input file %s\n",
X			       argv[optind]);
X			use_mess();
X			exit(1);
X		}
X		optind++;
X	}
X	if ((optind < argc) && (fp_disk == NULL)) {
X		if ((fp_disk = fopen(argv[optind], "w")) == NULL) {
X			printf("sorry, cannot open output file %s\n",
X			       argv[optind]);
X			use_mess();
X			exit(1);
X		}
X		optind++;
X		if (diskmode == NONE)
X			diskmode = CYCLE;
X	}
X	if (optind < argc) {
X		use_mess();
X		exit(1);
X	}
X	/* /dev/null may be needed as sink */
X	if ((fp_null = fopen("/dev/null", "w")) == NULL) {
X		fprintf(stderr, "\nCannot open /dev/null for output\n");
X		exit(1);
X	}
X	if (screenmode == NONE) {
X		screenmode = NONE;
X		fp_screen = fp_null;
X	}
X	if ((diskmode == NONE) || (fp_disk == NULL)) {
X		diskmode = NONE;
X		fp_disk = fp_null;
X	}
X	read_data(fp_screen, fp_input);
X	fclose(fp_input);
X
X	quad_cycle = quad_test;
X	nquad_skip = 0;
X
X	/* BEGIN LOOP */
X	/* simplex minimization alternates with quadratic fit */
X	while (TRUE) {
X		maxiter = iter + prt_cycle;
X
X		/* carry out simplex minimization */
X		if (screenmode == ALL)
X			simpfit(fp_screen);
X		else
X			simpfit(fp_null);
X
X		/* print summary of simplex fitting */
X		/* after page eject */
X		if ((screenmode >= CYCLE) || (iter != maxiter))
X			if (fp_screen != NULL)
X				ffitprint(fp_screen);
X		if ((diskmode >= CYCLE) || (iter != maxiter))
X			if (fp_disk != NULL)
X				ffitprint(fp_disk);
X
X		/* if test vs quad_test false, */
X		/* loop back to simpfit ; */
X		if (iter == maxiter) {
X			if (quad_test >= 1) {
X				if (iter < quad_test)
X					continue;
X			} else if (test > quad_test)
X				continue;
X		}
X		/* print data array */
X		/* after page eject */
X		if ((screenmode >= CYCLE) || (iter != maxiter))
X			if (fp_screen != NULL)
X				fdatprint(fp_screen);
X		if ((diskmode >= CYCLE) || (iter != maxiter))
X			if (fp_disk != NULL)
X				fdatprint(fp_disk);
X
X		/* carry out quadratic fit */
X		if (screenmode == ALL)
X			simpdev(fp_screen);
X		else
X			simpdev(fp_null);
X
X		/* print summary of results of quad fit */
X		/* after page eject */
X		if ((screenmode >= CYCLE) || (iter != maxiter))
X			if (fp_screen != NULL)
X				fquadprint(fp_screen);
X		if ((diskmode >= CYCLE) || (iter != maxiter))
X			if (fp_disk != NULL)
X				fquadprint(fp_disk);
X
X		/* exit if done = return on exit test true */
X		if (iter != maxiter) {
X			break;
X		}
X		/* increment nquad_skip if ypmin >= yzero */
X		if (ypmin < yzero)
X			nquad_skip = 0;
X		else if (nquad_skip < maxquad_skip)
X			nquad_skip++;
X
X		/* alter quad_test for next set of */
X		/* fitting cycles according to */
X		/* nquad_skip = the number of */
X		/* quadratic fit failures and quad_test */
X		/* greater or less than unity */
X		if (quad_test >= 1) {
X			if (iter >= quad_test)
X				quad_test = iter +
X					(nquad_skip + 1) * quad_cycle;
X		} else if (test <= quad_test)
X			quad_test = quad_test / 10;
X
X	}			/* END OF LOOP */
X
X	if (fp_disk != NULL)
X		fclose(fp_disk);
X	enditall();
X				/* NOT REACHED*/
X	return (0);
X}				/* END OF MAIN */
END_OF_FILE
if test 6789 -ne `wc -c <'./Lib/simpmain.c'`; then
    echo shar: \"'./Lib/simpmain.c'\" unpacked with wrong size!
fi
# end of './Lib/simpmain.c'
fi
echo shar: End of archive 3 \(of 4\).
cp /dev/null ark3isdone
MISSING=""
for I in 1 2 3 4 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 4 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0


