reaction
|
a.e,
a.m,
a.p,
a.s,
bail.c,
derivs.c,
errors,
extract.c,
extracter.c,
initial.c,
inlist.c,
lastchange,
makefile,
parse.c,
posting1,
rates.c,
reader.c,
readme,
reprint.c,
rxn.c,
rxn.h,
select.c,
setfiles.c,
wr_results.c,
wr_species.c,
|
|
|
/*
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.
*/
#include "rxn.h"
#define EXTRACT
/*
extract, format and print selected data
*/
extern int inlist();
extern void setfiles();
extern char *strtok();
#define LNS 64
int pr_line(n,lst) int n, *lst;
{
int num,i;
num = fread(Y,sizeof(double),NS+1,Ywrite);
if (num > 0)
{
printf("%15.4e ",Y[0]); /* time */
for (i = 1; i<=n; i++)printf("%15.4e ",Y[lst[i]]);
}
printf("\n");
return num;
}
void pr_header(n,spc) int n; char *spc[];
{
int i,j;
register char **cpp;
printf(" time");
for (cpp= &spc[1];cpp <= &spc[n]; cpp++) printf("%15s", *cpp);
printf("\n");
}
main(argc,argv) int argc; char **argv;
{
int i, num, lnct, l[20], k;
char line[4000], *name[20];
register char **cpp;
char *word;
char *tokens=" $ ,+;:(){}[]";
setfiles(argv[1]);
if ((Swrite = fopen(Species,"r"))==NULL) {
printf("ERROR ON OPEN\n");
exit (0);
}
fscanf(Swrite,"%d%d\n", &NR,&NS);
fgets(line,3999,Swrite);
fclose(Swrite);
line[(k=strlen(line))-1] = '\0';
SPECIES = (char *) malloc(k+1); strcpy(SPECIES,line);
#ifndef EXTRACT
printf("%d reacions involving %d species\n%s\n",NR,NS,SPECIES);
#endif
Y = (double *)malloc((NS+1)*sizeof(double));
if ((params = fopen(select,"r"))==NULL) {
printf("ERROR ON OPEN\n");
exit (0);
}
altlist = (char *)malloc(strlen(SPECIES)+1);
do {
fgets(line,3999,Swrite); line[strlen(line)-1] = '\0';
if ((k = strlen(line)) < 1) break;
if ((Ywrite = fopen(results,"r"))==NULL) {
printf("ERROR ON OPEN\n");
exit (0);
}
word = strtok(line,tokens);
k = 1;
while(word) {
i= inlist(SPECIES,word);
if (i> 0) {
cpp = &name[k];
*cpp = (char *)malloc(strlen(word) + 2 );
strcpy(*cpp,word);
l[k++] = i;
}
word = strtok(NULL,tokens);
}
k--;
lnct = 0;
do {
#ifndef EXTRACT
if (lnct == 0) pr_header(k,name);
#endif
num = pr_line(k,l);
lnct = (lnct > LNS ? 0: lnct+1);
}while (num > 0);
fclose(Ywrite);
while(k>0) { cpp = &name[k]; free(*cpp); k--;}
line[0] = '\0';
} while (1);
free(altlist);
}
|