📄 getall.c
字号:
#include "copyleft.h"
/*
GEPASI - a simulator of metabolic pathways and other dynamical systems
Copyright (C) 1989, 1992, 1993 Pedro Mendes
*/
/*************************************/
/* */
/* data input */
/* */
/* Zortech C/C++ 3.0 r4 */
/* MICROSOFT C 6.00 */
/* Visual C/C++ 1.0 */
/* QuickC/WIN 1.0 */
/* ULTRIX cc */
/* GNU gcc */
/* */
/* (include here compilers that */
/* compiled GEPASI successfully) */
/* */
/*************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef MSDOS
#include <io.h>
#endif
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <math.h>
#include "globals.h"
#include "globvar.h"
#include "datab.h"
#include "newton.h"
#include "strtbl.h"
#include "gauss.h"
#include "kinetics.h"
#include "pmu.h" /* several utilities */
#include "heapchk.h"
#if ( _MSC_VER >= 610 )
#define open _open
#define close _close
#define stat _stat
#define fstat _fstat
#define read _read
#define write _write
#define O_RDONLY _O_RDONLY
#endif
#ifdef _ZTC
#define MEM_DEBUG 1
#include "mem.h"
#else
#define mem_malloc malloc
#define mem_free free
#define mem_realloc realloc
#endif
/*
get the list of files to process
*/
void getlist( char *inpf )
{
int i;
FILE *chg;
if ( inpf )
{
if (!(chg=fopen(inpf,"r")))
{
printf(errormsg[6],inpf);
term_gepasi();
}
}
else
{
chg = stdin;
fprintf( stderr, "\n\n%s\n\n", gepasi );
fprintf( stderr, "input filenames one at a line, a dot followed by ENTER ends.\n\n");
}
for(i=0;i<MAX_FIL;i++) /* stop at MAX_FIL */
{
fgets( filename[i], PWIDTH, chg );
if ( ( filename[i][0] == '.' )
|| ( feof( chg ) )
) break; /* stop if EOF or . */
filename[i][strlen(filename[i])-1] = 0; /* put /0 at the end */
fixext( filename[i], '.', ".sim" );
}
nrunfiles = i;
if ( inpf ) fclose( chg );
return;
}
/*
read topology from file
*/
int BufToTop( char *Buff, char **endoftop )
{
int i,j;
int daux;
unsigned char uaux;
char *paux;
char saux[NAME_L];
/* reset the version number to zero */
ver_no = 0;
/* copy the first line */
paux = strchr( Buff, '\n' );
if( paux == NULL ) return IDS_ERR_BAD_TOPNAM;
/* take care of CR if one existed before LF */
if( *(paux-1)=='\r' ) *(paux-1) = '\0';
*paux = '\0';
if( strlen( Buff ) > 255 ) Buff[255] = '\0';
strcpy( topname, Buff );
Buff = paux+1;
/* is this line a version number ? */
sscanf( topname, "version %f", &ver_no );
if( ver_no != 0 )
{
/* YES! so let's read another line, with the title */
paux = strchr( Buff, '\n' );
if( paux == NULL ) return IDS_ERR_BAD_TOPNAM;
if( *(paux-1)=='\r' ) *(paux-1) = '\0';
*paux = '\0';
if( strlen( Buff ) > 255 ) Buff[255] = '\0';
strcpy( topname, Buff );
Buff = paux+1;
}
/* read nstep from the buffer */
if ( ( sscanf( Buff, " %d", &daux ) < 1) ||
( daux < 1 ) || ( daux > MAX_STEP ) )
return IDS_ERR_BAD_NSTEP;
nsteps = daux;
Buff = strchr( Buff, ' ' );
/* read totmet from the buffer */
if( (Buff == NULL ) || ( sscanf( ++Buff, " %d", &daux ) < 1) ||
( daux < 1 ) || ( daux > MAX_MET ) )
return IDS_ERR_BAD_TOTMET;
totmet = daux;
/* read stoiu from the buffer */
for(i=0;i<totmet;i++)
for(j=0;j<nsteps;j++)
{
if(j==0)
{
Buff = strchr( Buff, '\n' );
if( Buff != NULL )
{
Buff++;
for( ;*Buff == ' '; Buff++);
}
}
else
{
Buff = strchr( Buff, ' ' );
if( Buff != NULL ) for( ;*Buff == ' '; Buff++);
}
if ( (Buff == NULL) || (sscanf( Buff, "%d", &daux ) < 1) )
return IDS_ERR_BAD_STOI;
stoiu[i][j] = daux;
}
Buff = strchr( Buff, '\n' );
if( Buff == NULL ) return IDS_ERR_BAD_KINTYPE;
Buff++;
/* read kinetu, revers and metname from the buffer */
for( i=0; i<nsteps; i++ )
{
for( ;*Buff == ' '; Buff++);
if ( (Buff == NULL) || (sscanf( Buff, "%d", &daux ) < 1)
|| (daux < -1) )
return IDS_ERR_BAD_KINTYPE;
kinetu[i] = daux;
Buff = strchr( Buff, ' ' );
if( Buff != NULL ) for( ;*Buff == ' '; Buff++);
if ( (Buff == NULL) || (sscanf( Buff, "%d", &daux ) < 1) )
return IDS_ERR_BAD_KINTYPE;
revers[i] = daux;
Buff = strchr( Buff, ' ' );
if( Buff != NULL ) for( ;*Buff == ' '; Buff++);
paux = strchr( Buff, '\n' );
if( paux == NULL ) return IDS_ERR_BAD_KINTYPE;
/* take care of CR if one existed before LF */
if( *(paux-1)=='\r' ) *(paux-1) = '\0';
*paux = '\0';
if( strlen( Buff ) >= NAME_L ) Buff[NAME_L-1] = '\0';
strcpy( stepname[i], Buff );
Buff = paux+1;
}
*(--Buff) = '\n';
/* read rstr from the buffer */
for(i=0;i<nsteps;i++)
for(j=0;j<MAX_MOL;j++)
{
if(j==0)
{
Buff = strchr( Buff, '\n' );
if( Buff != NULL )
{
Buff++;
for( ;*Buff == ' '; Buff++);
}
}
else
{
Buff = strchr( Buff, ' ' );
if( Buff != NULL ) for( ;*Buff == ' '; Buff++);
}
if ( (Buff == NULL) || (sscanf( Buff,"%d", &daux ) < 1) )
return IDS_ERR_BAD_LOOP;
(*rstr)[i][j] = (signed char) daux;
}
/* read loop from the buffer */
for(i=0;i<nsteps;i++)
for(j=0;j<totmet;j++)
{
if(j==0)
{
Buff = strchr( Buff, '\n' );
if( Buff != NULL )
{
Buff++;
for( ;*Buff == ' '; Buff++);
}
}
else
{
Buff = strchr( Buff, ' ' );
if( Buff != NULL ) for( ;*Buff == ' '; Buff++);
}
if ( (Buff == NULL) || (sscanf( Buff,"%u", &uaux ) < 1)
|| (uaux < 0) )
return IDS_ERR_BAD_LOOP;
(*loop)[i][j] = uaux;
}
/* read metabolite status and names from the buffer */
for(i=0;i<totmet;i++)
{
Buff = strchr( Buff, '\n' );
if ( (Buff == NULL) || (sscanf( ++Buff, "%d %21s", &daux, saux ) < 2) )
return IDS_ERR_BAD_INTMET;
intmet[i] = daux;
strcpy( metname[i], saux );
}
/* point endofbuf to the end of the topology section */
if( endoftop != NULL )
*endoftop = Buff;
/* return and signal that function was successful */
return 0;
}
int BufToTree( char *Buff, char **endoftree )
{
int i;
char *paux;
int daux, daux1, daux2;
char caux[10];
float faux;
/* copy the title from the buffer */
paux = strchr( Buff, '\n' );
if( paux == NULL ) return IDS_ERR_LOAD;
/* take care of CR if one existed before LF */
if( *(paux-1)=='\r' ) *(paux-1) = '\0';
*paux = '\0';
if( strlen( Buff ) > 63 ) Buff[63] = '\0';
strcpy( tr.descr, Buff );
Buff = paux+1;
/* read nnode from the buffer */
if ( sscanf( Buff, "%d", &daux ) < 1 )
return IDS_ERR_LOAD;
tr.nnode = daux;
Buff = strchr( Buff, ' ' );
/* read nid from the buffer */
if( (Buff == NULL ) || ( sscanf( ++Buff, "%d", &daux ) < 1 ) )
return IDS_ERR_LOAD;
tr.nid = daux;
Buff = strchr( Buff, ' ' );
/* read nnum from the buffer */
if( (Buff == NULL ) || ( sscanf( ++Buff, "%d", &daux ) < 1 ) )
return IDS_ERR_LOAD;
tr.nnum = daux;
Buff = strchr( Buff, ' ' );
/* read nconst from the buffer */
if( (Buff == NULL ) || ( sscanf( ++Buff, "%d", &daux ) < 1 ) )
return IDS_ERR_LOAD;
tr.nconst = daux;
Buff = strchr( Buff, ' ' );
/* read nsub from the buffer */
if( (Buff == NULL ) || ( sscanf( ++Buff, "%d", &daux ) < 1 ) )
return IDS_ERR_LOAD;
tr.nsub = daux;
Buff = strchr( Buff, ' ' );
/* read npro from the buffer */
if( (Buff == NULL ) || ( sscanf( ++Buff, "%d", &daux ) < 1 ) )
return IDS_ERR_LOAD;
tr.npro = daux;
Buff = strchr( Buff, ' ' );
/* read nmodf from the buffer */
if( (Buff == NULL ) || ( sscanf( ++Buff, "%d", &daux ) < 1 ) )
return IDS_ERR_LOAD;
tr.nmodf = daux;
Buff = strchr( Buff, ' ' );
/* read revers from the buffer */
if( (Buff == NULL ) || ( sscanf( ++Buff, "%d", &daux ) < 1 ) )
return IDS_ERR_LOAD;
tr.revers = daux;
Buff = strchr( Buff, '\n' );
if( Buff==NULL ) return IDS_ERR_LOAD;
Buff++;
for( i=0; i<tr.nnode; i++ )
{
if( ( sscanf( Buff, "%c %d %d %d", &caux[0],
&daux,
&daux1,
&daux2 ) < 4 ) )
return IDS_ERR_LOAD;
tr.node[i].item = caux[0];
tr.node[i].val = (unsigned char) daux;
tr.node[i].left = (unsigned char) daux1;
tr.node[i].right = (unsigned char) daux2;
Buff = strchr( Buff, ',' );
if( Buff==NULL ) return IDS_ERR_LOAD;
Buff++;
}
for( i=0; i<tr.nid; i++ )
{
Buff = strchr( Buff, '\n' );
if( Buff==NULL ) return IDS_ERR_LOAD;
Buff++;
if( sscanf( Buff, "%d %8s", &daux, caux ) < 2 )
return IDS_ERR_LOAD;
strcpy( tr.id[i], caux );
tr.id[i][8] = '\0';
tr.id[i][9] = (char) daux;
}
for( i=0; i<tr.nnum; i++ )
{
Buff = strchr( Buff, '\n' );
if( Buff==NULL ) return IDS_ERR_LOAD;
Buff++;
if( sscanf( Buff, "%g", &faux ) < 1 )
return IDS_ERR_LOAD;
tr.constant[i] = faux;
}
/* point endofbuf to the end of the topology section */
if( endoftree != NULL )
*endoftree = Buff;
/**endoftree = strchr( Buff, '\n' );*/
return 0;
}
int BufToSim( char *Buff )
{
int i,j, dens, log, lkt, op, adj;
double faux, low, high, fac;
char *ptr;
char *paux;
/* read the kinetic constants from the buffer, one line per step */
for(i=0;i<nsteps;i++)
{
Buff = strchr( Buff, '\n' );
if( Buff != NULL ) Buff++;
for( j=0; j<(int)ktype[kinetype[i]].nconst; j++ )
{
Buff = strchr( Buff, ' ' );
if( Buff != NULL ) for( ;*Buff == ' '; Buff++);
if ( (Buff == NULL) || (sscanf( Buff,"%le", &faux ) < 1) )
return IDS_ERR_BAD_KPARAM;
*(params[i]+j) = faux;
}
}
/* read the concentrations, one per line */
for(i=0;i<totmet;i++)
{
Buff = strchr( Buff, '\n' );
if( Buff != NULL )
Buff++;
if ( (Buff == NULL) || (sscanf( Buff,"%le", &faux ) < 1) )
return IDS_ERR_BAD_CONCENT;
x0[i] = x[i] = faux;
}
/* read the units in one line */
Buff = strchr( Buff, '\n' );
if( Buff != NULL ) Buff++;
if ( (Buff == NULL) || (sscanf( Buff,"%s %s", &options.concu[0], &options.timeu[0] ) < 2) )
return IDS_ERR_BAD_UNITS;
/* read log, dyn and ss options in one line */
Buff = strchr( Buff, '\n' );
if( Buff != NULL )
Buff++;
if ( (Buff == NULL) || (sscanf( Buff,"%d %d %ld %le %le %le %le %d %d %d",
&options.debug, &options.dyn, &options.pfo, &options.endtime,
&options.reltol, &options.abstol, &options.hrcz, &options.adams,
&options.bdf, &options.ss ) < 10 ) )
return IDS_ERR_BAD_OPTIONS;
endtime = options.endtime;
/* read txt options in one line */
Buff = strchr( Buff, '\n' );
if( Buff != NULL )
Buff++;
if ( (Buff == NULL) || (sscanf( Buff,"%d %d %d %d %d %d %d",
&options.txt, &options.structan, &options.staban,
&options.stdela, &options.nonela, &options.stdcc,
&options.noncc ) < 7 ) )
return IDS_ERR_BAD_OPTIONS;
/* read the dat options in one line */
Buff = strchr( Buff, '\n' );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -