📄 iosim.c
字号:
return 0;
}
/*
read buffer with simulation parameters and store them
*/
int BufToSim( char *Buff )
{
int i, j, log, lkt, op;
unsigned long dens;
unsigned u_dummy;
double faux, low, high, fac;
char structfile[128], auxstr[128];
int nRc;
struct stat fst;
/* 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++;
else return IDS_ERR_BAD_KPARAM;
for( j=0; j<(int)ktype[kinetu[i]].nconst; j++ )
{
Buff = strchr( Buff, ' ' );
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++;
else return IDS_ERR_BAD_CONCENT;
if ( (Buff == NULL) || (sscanf( Buff,"%le", &faux ) < 1) )
return IDS_ERR_BAD_CONCENT;
xu[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, &options.timeu ) < 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;
/* 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' );
if( Buff != NULL )
Buff++;
if ( (Buff == NULL) || (sscanf( Buff,"%d %d %d %d %d %d %d %d %d",
&options.dat, &options.datsep, &options.datwidth,
&options.dattit, &options.datmca, &options.datss,
&totsel, &options.append, &options.quotes ) < 9 ) )
return IDS_ERR_BAD_OPTIONS;
/* read the dat filename in one line */
Buff = strchr( Buff, '\n' );
if( Buff != NULL )
Buff++;
if ( (Buff == NULL) || (sscanf( Buff,"%s", DatName ) != 1 ) )
return IDS_ERR_BAD_OPTIONS;
/* read each output item in one line (index only) */
for( i=0; i<totsel; i++ )
{
Buff = strchr( Buff, '\n' );
if( Buff != NULL )
Buff++;
if ( (Buff == NULL) || (sscanf( Buff,"%d", &j ) < 1 ) )
return IDS_ERR_BAD_OPTIONS;
if( ver_no < (float) 2.05 ) outpel[j+totmet].idx = i+1;
else outpel[j].idx = i+1;
}
/* read the scan options in one line */
Buff = strchr( Buff, '\n' );
if( Buff != NULL )
Buff++;
if ( (Buff == NULL) || (sscanf( Buff, "%d %lu %d %d %d", &options.scan,
&options.scandens, &options.scanlog,
&totscan, &nlinks ) < 5 ) )
return IDS_ERR_BAD_OPTIONS;
/* read each scan item in one line */
for( i=0; i<totscan; i++ )
{
Buff = strchr( Buff, '\n' );
if( Buff != NULL )
Buff++;
if ( (Buff == NULL) || (sscanf( Buff,"%d %le %le %lu %d", &j,
&low, &high, &dens, &log ) < 5 ) )
return IDS_ERR_BAD_OPTIONS;
spar[j].idx = i+1;
spar[j].low = low;
spar[j].high = high;
spar[j].dens = dens;
spar[j].log = log;
}
/* read each linked item in one line */
for( i=0; i<nlinks; i++ )
{
Buff = strchr( Buff, '\n' );
if( Buff != NULL )
Buff++;
if ( (Buff == NULL) || (sscanf( Buff,"%d %d %d %le", &j, &lkt, &op,
&fac ) < 4 ) )
return IDS_ERR_BAD_OPTIONS;
spar[j].lidx = i;
spar[j].linkedto = lkt;
spar[j].operation = op;
spar[j].factor = fac;
}
return 0;
}
/*
read simulation parameters from file
*/
int ReadSim( LPSTR FName )
{
HCURSOR hSaveCursor;
HANDLE hBuff;
unsigned int bufsize;
char *Buff;
int i, j, k, fl, ty, ch1, nRc;
OFSTRUCT OfStruct;
struct stat fst;
WORD sizetr;
/* display the wait cursor */
hSaveCursor = SetCursor(hHourGlass);
/* open the file */
if( (ch1 = OpenFile( FName, &OfStruct, OF_READ )) != -1 )
{
/* get the file statistics */
fstat( ch1, &fst );
/* set the buffer to the size of the file plus one */
bufsize = (unsigned int) fst.st_size;
/* allocate space for the read buffer and lock it */
hBuff = LocalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (WORD) (bufsize+1) );
if( hBuff == NULL )
{
SetCursor(hSaveCursor);
return IDS_ERR_LOAD;
}
Buff = (char *) LocalLock( hBuff );
/*read the file and close it */
if( read( ch1, Buff, bufsize ) == -1 )
{
LocalUnlock( hBuff );
LocalFree( hBuff );
SetCursor(hSaveCursor);
return IDS_ERR_LOAD;
}
if( close( ch1 ) == -1 )
{
LocalUnlock( hBuff );
LocalFree( hBuff );
SetCursor(hSaveCursor);
return IDS_ERR_LOAD;
}
/* set the number of user-def functions to zero */
nudf = 0;
nrateq = MAX_TYP;
sizetr = 4;
GlobalUnlock( hTreeStr );
GlobalFree( hTreeStr );
hTreeStr = GlobalAlloc( GMEM_ZEROINIT, sizetr );
if( hTreeStr == NULL )
{
LocalUnlock( hBuff );
LocalFree( hBuff );
SetCursor(hSaveCursor);
return IDS_ERR_NOEXEC;
}
treestr = GlobalLock( hTreeStr );
treeptr = treestr;
/* read the topology section */
if( nRc = BufToTop( Buff, &Buff ) )
{
LocalUnlock( hBuff );
LocalFree( hBuff );
SetCursor(hSaveCursor);
return nRc;
}
for( i=0; i<nsteps; i++ ) kfl[i] = 1;
/* check if model contains user-defined kinetic types */
/* if there are any, check if they have to be read */
for( i=0; i<nsteps; i++ )
if( (kinetu[i] >= MAX_TYP) && (kfl[i]) )
{
/* look for a form-feed */
Buff = strchr( Buff, '\f' );
Buff = BufToTree( ++Buff );
for( j=0, ty=-1; j<nudf; j++ )
if( lstrcmp( (LPSTR) tree[j].descr, (LPSTR) tr.descr ) == 0 )
{
ty = j;
break;
}
if( ty == -1 )
{
if( (nRc=addtr( i )) !=0 )
{
LocalUnlock( hBuff );
LocalFree( hBuff );
SetCursor(hSaveCursor);
return nRc;
}
fl = 1;
}
else
for( j=i,k=kinetu[i]; j<nsteps; j++ )
if( (kinetu[j]==k) && (kfl[j]) )
{
kinetu[j] = MAX_TYP+ty;
kfl[j] = 0;
}
}
/* setup the relevant databases */
if( nRc = setdb( 0 ) )
{
LocalUnlock( hBuff );
LocalFree( hBuff );
SetCursor(hSaveCursor);
return nRc;
}
/* read the simulation section */
nRc = BufToSim( Buff );
LocalUnlock( hBuff );
LocalFree( hBuff );
SetCursor(hSaveCursor);
return nRc;
}
else
{
SetCursor(hSaveCursor);
return IDS_ERR_LOAD;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -