#!/bin/sh

if [ $# -eq 0 ] 
then
	root="scr"
else
	root="$1"
fi

# create root.m file
cat <<EOF | grep -v "^#" >${root}.m
#rate constant		reactants -> products
4.e7	E + S -> ES
2.e3	ES -> E + S
4.e3	ES -> EX
2.e3	EX -> E + P
EOF

# create root.p file
cat <<EOF | grep -v "^#" >${root}.p
#iopt
1
#itol	istate	jt	itask
4	1	2	1
#ml	mu	ixpr	mxstep	mxhnil	mxordn	mxords
#iwork1	iwork2	iwork5	iwork6	iwork7	iwork8	iwork9
0	0	0	500	0	0	0
#tcrit	h0	hmax	hmin
#rwork1	rwork5	rwork6	rwork7
0.	0.	0.	0.
#start_time  end_time  {time_step|0}  deflt_tolerance  [first_time  time_factor]
#0.0	0.0001	.000003	1.0e-10
#0	1.0e6	0	1.0e-10	1.e-9	1.2589253
0	1.0e6	0	1.0e-10	1.e-9	1.2589254117
#species	initial concn		absol. tolerance	relat. tolerance
E	1.e-4	1.e-15	1.e-10
S	1.e-4	1.e-15	1.e-10
ES	0	1.e-15	1.e-10
P	0	1.e-15	1.e-10
EOF

#run it 
react ${root} >${root}.r 

#and graph it
cat ${root}.r | prep | ttygraph
