gep1.c

来自「GESPI 2.0动态系统模拟工具  」· C语言 代码 · 共 621 行 · 第 1/2 页

C
621
字号
 ktype[PCI].nmodf = 1;
 ktype[PCI].descr = (LPSTR) "catalytic inhibition";
 ktype[MXI].nsub = 1;
 ktype[MXI].npro = 1;
 ktype[MXI].revers = 1;
 ktype[MXI].nmodf = 1;
 ktype[MXI].descr = (LPSTR) "mixed inhibition";
 ktype[PSA].nsub = 1;
 ktype[PSA].npro = 1;
 ktype[PSA].revers = 1;
 ktype[PSA].nmodf = 1;
 ktype[PSA].descr = (LPSTR) "specific activation";
 ktype[PCA].nsub = 1;
 ktype[PCA].npro = 1;
 ktype[PCA].revers = 1;
 ktype[PCA].nmodf = 1;
 ktype[PCA].descr = (LPSTR) "catalytic activation";
 ktype[MXA].nsub = 1;
 ktype[MXA].npro = 1;
 ktype[MXA].revers = 1;
 ktype[MXA].nmodf = 1;
 ktype[MXA].descr = (LPSTR) "mixed activation";
 ktype[GOM].nsub = 20;
 ktype[GOM].npro = 20;
 ktype[GOM].revers = 1;
 ktype[GOM].nmodf = 1;
 ktype[GOM].descr = (LPSTR) "Botts-Morales";
 ktype[HIL].nsub = 1;
 ktype[HIL].npro = 1;
 ktype[HIL].revers = 0;
 ktype[HIL].nmodf = 0;
 ktype[HIL].descr = (LPSTR) "Hill";
 ktype[RHL].nsub = 20;
 ktype[RHL].npro = 20;
 ktype[RHL].revers = 1;
 ktype[RHL].nmodf = 0;
 ktype[RHL].descr = (LPSTR) "reversible Hill";
 ktype[UBS].nsub = 1;
 ktype[UBS].npro = 2;
 ktype[UBS].revers = 1;
 ktype[UBS].nmodf = 0;
 ktype[UBS].descr = (LPSTR) "Ordered Uni Bi (A=P+Q)";
 ktype[UBM].nsub = 1;
 ktype[UBM].npro = 1;
 ktype[UBM].revers = 1;
 ktype[UBM].nmodf = 0;
 ktype[UBM].descr = (LPSTR) "Ordered Uni Bi (A=2*P)";
 ktype[ALI].nsub = 1;
 ktype[ALI].npro = 1;
 ktype[ALI].revers = 1;
 ktype[ALI].nmodf = 1;
 ktype[ALI].descr = (LPSTR) "allosteric inhibition";

 if( (i = in_kinet()) )
 {
  LoadString( hInst, i, szString, sizeof(szString) );
  MessageBeep( MB_ICONQUESTION );
  MessageBox( NULL, szString, (LPSTR) "user-def.kin", MB_ICONINFORMATION );
 }
 return 0;
}

/*
   output error message from the lexical analyser
*/

int lexyy_fatal( char *m )
{
 MessageBeep( MB_OK );
 MessageBox( NULL, (LPSTR) m, (LPSTR) "Lexical Analyser Error", MB_ICONINFORMATION );
 return 0;
}

/*
   create a new function tree object
*/

int new_tree( int idx )
{
 if( !eqefl )
 {
  nudf++;
  GlobalUnlock( hTree );
  hTree = GlobalReAlloc( hTree, (DWORD) nudf * sizeof( struct treet ), GMEM_ZEROINIT | GMEM_MOVEABLE );
  if( hTree == NULL )
   return IDS_ERR_NOEXEC;
  tree = ( struct treet huge * ) GlobalLock( hTree );
 }
 _fmemcpy( (void __far *) &tree[idx], (void __far *) &tr, sizeof( struct treet ) );
 newtree = 1;
 return 0;
}

/*
  count the number of substrates, etc. in the function tree
  and allocate memory for the string with the title
*/

void tidy_tree( void )
{
 int i, l;

 for( tr.nsub =
      tr.npro =
      tr.nmodf =
      tr.nconst =
      i = 0; i<tr.nid; i++ )
  switch( (int) tr.id[i][9] )
  {
   case 0: tr.nconst++; break;
   case 1: tr.nsub++; break;
   case 2: tr.npro++; break;
   case 3: tr.nmodf++; break;
  }
}


/*
   read the user-defined kinetic types in the database
*/

int in_kinet( void )
{
 GLOBALHANDLE hTemp;
 HANDLE hBuff;
 OFSTRUCT OfStruct;
 struct stat fst;
 unsigned int bufsize;
 char *Buff;
 char fn[128], *ptr;
 int ch1;
 int nRc;

 /* make the complete pathname of user-def.kin			*/
 GetModuleFileName( hInst, (LPSTR) fn, sizeof( fn ) );
 ptr = strrchr( fn, '\\' );
 *(ptr+1) = '\0';
 lstrcat( (LPSTR) fn, (LPSTR) "user-def.kin" );

 /* open the file													*/
 ch1 = OpenFile( fn, &OfStruct, OF_READ );
 if( ch1 != -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_DISCARDABLE, (WORD) (bufsize+1) );
  if( hBuff == NULL ) return IDS_ERR_NOEXEC;
  Buff = (char *) LocalLock( hBuff );

  /*read the file and close it										*/
  if( read( ch1, Buff, bufsize ) == -1 )
  {
   LocalUnlock( hBuff );
   LocalFree( hBuff );
   return IDS_ERR_LOAD;
  }
  close( ch1 );

  for( ; ; )
  {
   /* look for a form-feed											*/
   Buff = strchr( Buff, '\f' );
   if( Buff==NULL )
   {
    LocalUnlock( hBuff );
    LocalFree( hBuff );
    return 0;
   }
   Buff++;
   /* create a new tree structure to hold this kinetic type			*/
   eqefl = 0;
   new_tree( nudf );
   /* get another tree from the buffer								*/
   if( (Buff = BufToTree( Buff ) ) == NULL )
   {
    LocalUnlock( hBuff );
    LocalFree( hBuff );
    return IDS_ERR_DATAB_CORRUPT;
   }
   /* copy the tree structure to the permanent storage				*/
   _fmemcpy( (void __far *) &tree[nudf-1], (void __far *) &tr, sizeof( struct treet ) );
   /* store the new type in ktype									*/
   GlobalUnlock( hKtype );
   hTemp = GlobalReAlloc( hKtype, (DWORD) (nrateq+1) * sizeof( struct kint ), GMEM_ZEROINIT | GMEM_MOVEABLE );
   if( hTemp != NULL )
   {
    hKtype = hTemp;
    ktype = ( struct kint huge * ) GlobalLock( hKtype );
    ktype[nrateq].nsub = (unsigned char) tree[nudf-1].nsub;
    ktype[nrateq].npro = (unsigned char) tree[nudf-1].npro;
    ktype[nrateq].revers = (unsigned char) tree[nudf-1].revers;
    ktype[nrateq].nmodf = (unsigned char) tree[nudf-1].nmodf;
    ktype[nrateq].descr = (LPSTR) tree[nudf-1].descr;
    nrateq++;
   }
   else
   {
    ktype = ( struct kint huge * ) GlobalLock( hKtype );
    LocalUnlock( hBuff );
    LocalFree( hBuff );
    return IDS_ERR_NOEXEC;
   }
  }
 }
 else return 0; /*IDS_ERR_LOAD;*/
}

/*
   write the user-defined kinetic types in the database
*/

int out_tree( void )
{
 char Buff[5500];
 int ch1;
 OFSTRUCT OfStruct;
 char fn[128], *ptr;
 int i;

 /* make the complete pathname of user-def.kin			*/
 GetModuleFileName( hInst, (LPSTR) fn, sizeof( fn ) );
 ptr = strrchr( fn, '\\' );
 *(ptr+1) = '\0';
 lstrcat( (LPSTR) fn, (LPSTR) "user-def.kin" );

 /* first create the file												*/
 if( (ch1 = OpenFile( fn, &OfStruct, OF_CREATE | OF_WRITE )) == -1 )
  return IDS_ERR_SAVE;
 close( ch1 );

 /* for all user-defined kinetic types									*/
 for( i=0; i<nudf; i++ )
 {
  /* write the tree function to the buffer								*/
  TreeToBuf( i, (LPSTR) Buff );
  /* reopen the file and write this tree to it							*/
  if( (ch1 = OpenFile( (LPSTR) NULL, &OfStruct, OF_REOPEN | OF_WRITE )) != -1 )
  {
   /* write the buffer to the file and close it							*/
   _lseek( ch1, (LONG) 0, 2 );
   _lwrite( ch1, (LPSTR) Buff, (WORD) strlen( Buff ) );
   _lclose( ch1 );
  }
  if( ch1 == -1 ) return IDS_ERR_SAVE;
 }
 return 0;
}


/*
  add a user-defined rate equation to the database
*/

int new_rateq( int idx )
{
 GLOBALHANDLE hTemp;

 /* unlock the memory handle	*/
 GlobalUnlock( hKtype );
 hTemp = GlobalReAlloc( hKtype, (DWORD) (nrateq+1) * sizeof( struct kint ), GMEM_ZEROINIT | GMEM_MOVEABLE );
 if( hTemp != NULL )
 {
  hKtype = hTemp;
  ktype = ( struct kint huge * ) GlobalLock( hKtype );
  ktype[MAX_TYP+idx].nsub = (unsigned char) tree[idx].nsub;
  ktype[MAX_TYP+idx].npro = (unsigned char) tree[idx].npro;
  ktype[MAX_TYP+idx].revers = (unsigned char) tree[idx].revers;
  ktype[MAX_TYP+idx].nmodf = (unsigned char) tree[idx].nmodf;
  ktype[MAX_TYP+idx].descr = (LPSTR) tree[idx].descr;
  if( !eqefl ) nrateq++;
  return 0;
 }
 else
 {
  ktype = ( struct kint huge * ) GlobalLock( hKtype );
  return IDS_ERR_NOEXEC;
 }
}


/*
  free global heap space allocated
*/

void TidyGepasiVar( void )
{
 GlobalUnlock( hMetname );							/* unlock all global handles	*/
 GlobalUnlock( hStepname );
 GlobalUnlock( hStoiu );
 GlobalUnlock( hLoop );
 GlobalUnlock( hRstr );
 GlobalUnlock( hKtype );
 GlobalUnlock( hTree );

 GlobalFree( hMetname );							/* free all global mem blocks	*/
 GlobalFree( hStepname );
 GlobalFree( hStoiu );
 GlobalFree( hLoop );
 GlobalFree( hRstr );
 GlobalFree( hKtype );
 GlobalFree( hTree );
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?