/*
 * The permission is granted to use the software as is and redistribute it in
 * its original and complete form. If you find this program useful and
 * publish results obtained by it, please cite the program as: Michael
 * Whitbeck, Desert Research Institute, 1991, "REACT - Program to solve
 * kinetic equations for chemical systems". Version 1.00, this code is
 * available from the authors or from Dr. Whitbeck.
 */

/*
 * derivs
 */

#include "rxn.h"

extern RXN     *reaction;

void
derivs(neq, t, y, ydot)
	double          t, *y, *ydot;
	int             neq;	/* == num_species */
{
	int             i;
	RXN            *pr;
	SPECIES        *ps;

	for (i = 1; i <= neq; i++)
		ydot[i] = 0.0;
	for (pr = reaction; pr != NULL; pr = pr->next) {
		pr->rate = pr->k;
		for (ps = pr->reactant; ps != NULL; ps = ps->next)
			pr->rate *= y[ps->id];
		for (ps = pr->reactant; ps != NULL; ps = ps->next)
			ydot[ps->id] -= pr->rate;
		for (ps = pr->product; ps != NULL; ps = ps->next)
			ydot[ps->id] += pr->rate;
	}
}
