⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gaussw.c

📁 GESPI 2.0动态系统模拟工具  
💻 C
📖 第 1 页 / 共 2 页
字号:
 nmetab = k;                               /* the no.of internal metabolites */
}

void ext_ord( void )                       /* now put the declared exernal   */
{                                          /* metabolites in the last rows   */
 register int i,j,k;                       /* of stoi                        */

 k = nmetab;
 for( i=0; i<totmet; i++ )
  if (!intmet[i])
  {
   ur[k] = i;                              /* record the old number          */
   for( j=0; j<nsteps; j++ )
    stoi[k*MAX_MET + j] = stoiu[i*MAX_MET + j];
   k++;
  }
 nextmet = totmet - nmetab;                /* the no.of external metabolites */
}

void initreds( void )
{
 register int i,j;

 for( i=0; i<nmetab; i++)
 {
  for( j=0; j<nsteps; j++)
   rstoi[i*MAX_MET + j] = (float) stoi[i*MAX_MET + j];              /* init rstoi from stoi    */
  for( j=0; j<nmetab; j++)
   ml[i*MAX_MET + j] = (float) 0;                          /* init matrix of multipl. */
 }
}

void more_ext( void)
{
 register int i;

 for( i=0; i<nmetab; i++ )                        /* get rid of empty rows   */
 {                                                /* which are xtrnl metabs. */
  if ( ! emptyrow( i, nsteps ) )                  /* all entries in row = 0  */
  {
   rowsw( i, nmetab-1, nsteps );                  /* put row at the end      */
   intmet[ur[nmetab]] = 0;                        /* signal this 1 is xtrnl! */
   nmetab--;                                      /* signal 1 less int. met. */
   nextmet++;                                     /* and 1 more extern. met. */
  }
 }
}

void virt_step( void )
{
 register int i, j, ct;

 for( i=0; i<nsteps; i++ )                        /* get rid of empty cols   */
 {                                                /* which are 0 rate steps  */
  for( ct=0, j=0; j<nmetab; j++)
   if ( fabs( rstoi[j*MAX_MET + i] ) > ALMOST_ZERO ) ct++; /* ct counts entries != 0  */
  if ( !ct )                                      /* all entries in col = 0  */
  {
   colsw( i, nsteps-1, nmetab );                  /* put col at the end      */
   nsteps--;                                      /* one less active step    */
  }
 }
}

int reduce( int swapnames )
{
 int i, j, k, ix, s;
 int kinetype[MAX_STEP];							/* type of kinetics (user numb.)		*/

 /* first lets allocate memory for mirrors and aux matrices	*/

 hRSto = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) MAX_MET * MAX_STEP * sizeof( float ) );
 if( hRSto == NULL )
  return IDS_ERR_OUT_OF_MEM;
 hMetn = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) MAX_MET * NAME_L * sizeof( char ) );
 if( hMetn == NULL )
 {
  GlobalFree( hRSto );
  return IDS_ERR_OUT_OF_MEM;
 }
 hStepn = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) MAX_STEP * NAME_L * sizeof( char ) );
 if( hStepn == NULL )
 {
  GlobalFree( hMetn );
  GlobalFree( hRSto );
  return IDS_ERR_OUT_OF_MEM;
 }
 hStepst = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) MAX_STEP * 256 * sizeof( char ) );
 if( hStepst == NULL )
 {
  GlobalFree( hStepn );
  GlobalFree( hMetn );
  GlobalFree( hRSto );
  return IDS_ERR_OUT_OF_MEM;
 }
 hMl = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) MAX_MET * MAX_MET * sizeof( float ) );
 if( hMl == NULL )
 {
  GlobalFree( hStepn );
  GlobalFree( hStepst );
  GlobalFree( hMetn );
  GlobalFree( hRSto );
  return IDS_ERR_OUT_OF_MEM;
 }
 hLm = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) MAX_MET * MAX_MET * sizeof( float ) );
 if( hLm == NULL )
 {
  GlobalFree( hMl );
  GlobalFree( hStepst );
  GlobalFree( hStepn );
  GlobalFree( hMetn );
  GlobalFree( hRSto );
  return IDS_ERR_OUT_OF_MEM;
 }
 hLD = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) MAX_MET * MAX_MET * sizeof( float ) );
 if( hLD == NULL )
 {
  GlobalFree( hLm );
  GlobalFree( hMl );
  GlobalFree( hStepst );
  GlobalFree( hStepn );
  GlobalFree( hMetn );
  GlobalFree( hRSto );
  return IDS_ERR_OUT_OF_MEM;
 }
 hImet = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) MAX_MET * sizeof( int ) );
 if( hImet == NULL )
 {
  GlobalFree( hLD );
  GlobalFree( hLm );
  GlobalFree( hMl );
  GlobalFree( hStepst );
  GlobalFree( hStepn );
  GlobalFree( hMetn );
  GlobalFree( hRSto );
  return IDS_ERR_OUT_OF_MEM;
 }
 hRs = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) MAX_STEP * MAX_MOL * sizeof( int ) );
 if( hRs == NULL )
 {
  GlobalFree( hImet );
  GlobalFree( hLD );
  GlobalFree( hLm );
  GlobalFree( hMl );
  GlobalFree( hStepst );
  GlobalFree( hStepn );
  GlobalFree( hMetn );
  GlobalFree( hRSto );
  return IDS_ERR_OUT_OF_MEM;
 }
 hLoo = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) MAX_STEP * MAX_MET * sizeof( int ) );
 if( hLoo == NULL )
 {
  GlobalFree( hRs );
  GlobalFree( hImet );
  GlobalFree( hLD );
  GlobalFree( hLm );
  GlobalFree( hMl );
  GlobalFree( hStepst );
  GlobalFree( hStepn );
  GlobalFree( hMetn );
  GlobalFree( hRSto );
  return IDS_ERR_OUT_OF_MEM;
 }
 /* and lock the memory blocks			*/
 rstoi	= (float huge *) GlobalLock( hRSto );
 metn	= (char (huge *)[NAME_L]) GlobalLock( hMetn );
 stepn	= (char (huge *)[NAME_L]) GlobalLock( hStepn );
 stepst	= (char (huge *)[256]) GlobalLock( hStepst );
 ml		= (float huge *) GlobalLock( hMl );
 lm		= (float huge *) GlobalLock( hLm );
 ld		= (float huge *) GlobalLock( hLD );
 imet	= (int huge *) GlobalLock( hImet );
 rs		= (int (huge *)[MAX_MET][MAX_MOL]) GlobalLock( hRs );
 loo	= (int huge *) GlobalLock( hLoo );

 for( i=0; i<nsteps; i++) uc[i] = i;       /* setup reaction perm. vector    */
 for( i=0; i<totmet; i++) ur[i] = i;       /* setup metabolite perm. vector  */

 int_ord();                                /* put int. metabs. at the beggin.*/
 ext_ord();                                /* put ext. metabs. at the end    */
 initreds();                               /* reset rstoi and ml             */
 more_ext();                               /* spot implicit external metabs. */
 virt_step();                              /* spot virtual steps             */
 gauss();                                  /* stoi -> rstoi by gaussian red. */

 /* make the mirrors be indexed by the new mapping		*/
 /* if swapnames remap metabolite and step names		*/

 for( i=0; i<nsteps; i++ )
 {
  if( swapnames )
  {
   lstrcpy( (LPSTR) stepn[i], (LPSTR) stepname[uc[i]] );
   lstrcpy( (LPSTR) stepst[i], (LPSTR) stepstr[uc[i]] );
   kinetype[i] = kinetu[uc[i]];
   for(j=0;j<totmet;j++)
    loo[MAX_STEP*i+j] = (*loop)[uc[i]][ur[j]];
   for(j=0;j<MAX_MOL;j++)
   {
    ix = (*rstr)[uc[i]][j];
    if( ix == 0 )
    {
     (*rs)[i][j] = 0;
     continue;
    }
    s = ix/ abs( ix );  /*the signal*/
    ix = abs( ix )-1;   /*the index */
    for( k=0; k<totmet; k++ )
     if( ix == ur[k] ) break;
    (*rs)[i][j] = s*(k+1);
   }
  }
  else
  {
   lstrcpy( (LPSTR) stepn[i], (LPSTR) stepname[i] );
   lstrcpy( (LPSTR) stepst[i], (LPSTR) stepstr[i] );
   kinetype[i] = kinetu[i];
   for(j=0;j<totmet;j++)
    loo[MAX_STEP*i+j] = (*loop)[i][j];
   for(j=0;j<MAX_MOL;j++)
    (*rs)[i][j] = (*rstr)[i][j];
  }
 }
/*  if( swapnames )
  {
   for( i=0; i<nsteps; i++)
    for(j=0;j<MAX_MOL;j++)
    {
     if( (*rstr)[uc[i]][j] > 0 )
      (*rs)[i][j] = ur[(*rstr)[uc[i]][j] - 1] + 1;
     else
      if( (*rstr)[uc[i]][j] < 0 )
       (*rs)[i][j] = -ur[-(*rstr)[uc[i]][j] - 1] - 1;
      else
       (*rs)[i][j] = 0;
    }
  }  */

 for( i=0; i<totmet; i++ )
  if( swapnames )
  {
   lstrcpy( (LPSTR) metn[i], (LPSTR) metname[ur[i]] );
   imet[i] = intmet[ur[i]];
  }
  else
  {
   lstrcpy( (LPSTR) metn[i], (LPSTR) metname[i] );
   imet[i] = intmet[i];
  }

 /* copy everything back to the original structures		*/
 _fmemcpy( (void __far *) metname,
  	       (void __far *) metn,
   	       (size_t) MAX_MET * NAME_L * sizeof( char ) );
 _fmemcpy( (void __far *) stepname,
   	       (void __far *) stepn,
   	       (size_t) MAX_STEP * NAME_L * sizeof( char ) );
 _fmemcpy( (void __far *) stepstr,
   	       (void __far *) stepst,
   	       (size_t) MAX_STEP * 256 * sizeof( char ) );
 _fmemcpy( (void __far *) kinetu,
   	       (void __far *) kinetype,
           (size_t) MAX_STEP * sizeof( int ) );
 _fmemcpy( (void __far *) intmet,
   	       (void __far *) imet,
           (size_t) MAX_MET * sizeof( int ) );
 _fmemcpy( (void __far *) rstr,
   	       (void __far *) rs,
           (size_t) MAX_STEP * MAX_MOL * sizeof( int ) );
 for(i=0;i<nsteps;i++)
  for(j=0;j<totmet;j++)
   (*loop)[i][j]  = (unsigned char) loo[MAX_STEP*i+j];

 lindep();                                 /* work out linear dependencies   */

 /* unlock and free the mirrors							*/
 GlobalUnlock( hLoo );
 GlobalUnlock( hRs );
 GlobalUnlock( hImet );
 GlobalUnlock( hLD );
 GlobalUnlock( hLm );
 GlobalUnlock( hMl );
 GlobalUnlock(  hStepst );
 GlobalUnlock( hStepn );
 GlobalUnlock( hMetn );
 GlobalUnlock( hRSto );
 GlobalFree( hLoo );
 GlobalFree( hRs );
 GlobalFree( hImet );
 GlobalFree( hLD );
 GlobalFree( hLm );
 GlobalFree( hMl );
 GlobalFree(  hStepst );
 GlobalFree( hStepn );
 GlobalFree( hMetn );
 GlobalFree( hRSto );
 return 0;
}

⌨️ 快捷键说明

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