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

📄 iotop.c

📁 GESPI 2.0动态系统模拟工具  
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "copyleft.h"

/*
    GEPASI - a simulator of metabolic pathways and other dynamical systems
    Copyright (C) 1989, 1992, 1993  Pedro Mendes
*/

/*************************************/
/*                                   */
/*        MS-WINDOWS front end       */
/*                                   */
/*         Topology files I/O        */
/*                                   */
/*          QuickC/WIN 1.0           */
/*                                   */
/*   (include here compilers that    */
/*   compiled GWSIM successfully)    */
/*                                   */
/*************************************/


/*
  this file is used both by GWSIM and GWTOP and GWTOP
  must define the symbol GWTOP, otherwise, this file
  will generate stuff for GWSIM
*/

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <io.h>
#include <sys\types.h>
#include <sys\stat.h>
#include "globals.h"
#include "iotop.h"
#include "strtbl.h"						/* symbols for the string table			*/
#ifdef GWTOP
#include "gwtop.h"
#include "topgvar.h"
#include "gep1.h"
#else
#include "gwsim.h"
#include "simgvar.h"
#include "gep2.h"
#endif

#pragma alloc_text( CODE12, TreeToBuf, BufToTree, TopToBuf, WriteTop, BufToTop, ReadTop )

/* write a rate equation tree to a buffer							*/

void TreeToBuf( int i, LPSTR Buff )
{
 char a1[128];
 int j;

 wsprintf( (LPSTR) Buff, "\f%s\n", (LPSTR) tree[i].descr );
 wsprintf( (LPSTR) a1, "%d %d %d %d %d %d %d %d\n", tree[i].nnode,
                                           		    tree[i].nid,
                                                    tree[i].nnum,
                                                    tree[i].nconst,
                                                    tree[i].nsub,
                                                    tree[i].npro,
                                                    tree[i].nmodf,
                                                    tree[i].revers );
 lstrcat( Buff, (LPSTR) a1 );
 for( j=0; j<tree[i].nnode; j++ )
 {
  wsprintf( (LPSTR) a1, "%c %d %d %d,", tree[i].node[j].item, (int) tree[i].node[j].val,
                                  (int) tree[i].node[j].left, (int) tree[i].node[j].right );
  lstrcat( Buff , (LPSTR) a1 );
 }
 lstrcat( Buff, (LPSTR) "\n" );
 for( j=0; j<tree[i].nid; j++ )
 {
  wsprintf( (LPSTR) a1, "%d %s\n", (int) tree[i].id[j][9], (LPSTR) tree[i].id[j] );
  lstrcat( Buff, (LPSTR) a1 );
 }
 for( j=0; j<tree[i].nnum; j++ )
 {
  gcvt( tree[i].constant[j], 8, a1 );
  lstrcat( Buff, (LPSTR) a1 );
  lstrcat( Buff, (LPSTR) "\n" );
 }
}


char *BufToTree( char *Buff )
{
 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 (char *) NULL;
 /* 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';
 lstrcpy( (LPSTR) tr.descr, (LPSTR) Buff );
 Buff = paux+1;

 /* read nnode from the buffer										*/
 if ( sscanf( Buff, "%d", &daux ) < 1 )
  return (char *) NULL;
 tr.nnode = daux;

 Buff = strchr( Buff, ' ' );
 /* read nid from the buffer										*/
 if( (Buff == NULL ) || ( sscanf( ++Buff, "%d", &daux ) < 1 ) )
  return (char *) NULL;
 tr.nid = daux;

 Buff = strchr( Buff, ' ' );
 /* read nnum from the buffer										*/
 if( (Buff == NULL ) || ( sscanf( ++Buff, "%d", &daux ) < 1 ) )
  return (char *) NULL;
 tr.nnum = daux;

 Buff = strchr( Buff, ' ' );
 /* read nconst from the buffer									*/
 if( (Buff == NULL ) || ( sscanf( ++Buff, "%d", &daux ) < 1 ) )
  return (char *) NULL;
 tr.nconst = daux;

 Buff = strchr( Buff, ' ' );
 /* read nsub from the buffer										*/
 if( (Buff == NULL ) || ( sscanf( ++Buff, "%d", &daux ) < 1 ) )
  return (char *) NULL;
 tr.nsub = daux;

 Buff = strchr( Buff, ' ' );
 /* read npro from the buffer										*/
 if( (Buff == NULL ) || ( sscanf( ++Buff, "%d", &daux ) < 1 ) )
  return (char *) NULL;
 tr.npro = daux;

 Buff = strchr( Buff, ' ' );
 /* read nmodf from the buffer									*/
 if( (Buff == NULL ) || ( sscanf( ++Buff, "%d", &daux ) < 1 ) )
  return (char *) NULL;
 tr.nmodf = daux;

 Buff = strchr( Buff, ' ' );
 /* read revers from the buffer									*/
 if( (Buff == NULL ) || ( sscanf( ++Buff, "%d", &daux ) < 1 ) )
  return (char *) NULL;
 tr.revers = daux;

 Buff = strchr( Buff, '\n' );
 if( Buff==NULL ) return (char *) NULL;
 Buff++;

 for( i=0; i<tr.nnode; i++ )
 {
  if( ( sscanf( Buff, "%c %d %d %d", &caux[0],
                                     &daux,
                                     &daux1,
                                     &daux2 ) < 4 ) )
   return (char *) NULL;
  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 (char *) NULL;
  Buff++;
 }
 for( i=0; i<tr.nid; i++ )
 {
  Buff = strchr( Buff, '\n' );
  if( Buff==NULL ) return (char *) NULL;
  Buff++;
  if( sscanf( Buff, "%d %8s", &daux, caux ) < 2 )
   return (char *) NULL;
  lstrcpy( tr.id[i], (LPSTR) 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 (char *) NULL;
  Buff++;
  if( sscanf( Buff, "%g", &faux ) < 1 )
   return (char *) NULL;
  tr.constant[i] = faux;
 }
/*Buff = strchr( Buff, '\n' );*/
 return Buff;
}


void TopToBuf( LPSTR Buff )
{
 int i, j;
 char auxstr[260];

 /* first line: version number											*/
 wsprintf( (LPSTR) Buff, FILE_VERSION );
 /* topology's title in one line										*/
 wsprintf( (LPSTR) auxstr, "%s\n", (LPSTR) topname );
 lstrcat( Buff, (LPSTR) auxstr);
 /* number of steps and metabolites	in one line							*/
 wsprintf( (LPSTR) auxstr, "%d %d\n", nsteps, totmet );
 lstrcat( Buff, (LPSTR) auxstr);
 /* stoicheiometry matrix												*/
 for(i=0;i<totmet;i++)
 {
  for(j=0;j<nsteps;j++)
  {
#ifdef GWTOP
   wsprintf( (LPSTR) auxstr, "%2d ", stoiu[i*MAX_MET + j] );
#else
   wsprintf( (LPSTR) auxstr, "%2d ", stoi[i*MAX_MET + j] );
#endif
   lstrcat( Buff, (LPSTR) auxstr);
  }
  lstrcat( Buff, (LPSTR) "\n" );
 }
 /* kinetic types, reversability status and step names, one per line	*/
 for(i=0;i<nsteps;i++)
 {
  wsprintf( (LPSTR) auxstr, "%2d %2d %s\n", kinetu[i],
  										    revers[i],
  											(LPSTR) stepname[i] );
  lstrcat( Buff, (LPSTR) auxstr);
 }
 /* rstr matrix															*/
 for(i=0;i<nsteps;i++)
 {
  for(j=0;j<MAX_MOL;j++)
  {
   wsprintf( (LPSTR) auxstr, "%2d ", (*rstr)[i][j] );
   lstrcat( Buff, (LPSTR) auxstr);
  }
  lstrcat( Buff, (LPSTR) "\n" );
 }
 /* loop matrix															*/
 for(i=0;i<nsteps;i++)
 {
  for(j=0;j<totmet;j++)
  {
   wsprintf( (LPSTR) auxstr, "%2d ", (*loop)[i][j] );
   lstrcat( Buff, (LPSTR) auxstr);
  }
  lstrcat( Buff, (LPSTR) "\n" );
 }
 /* metabolite status and names, one per line										*/
 for(i=0;i<totmet;i++)
 {
  wsprintf( (LPSTR) auxstr, "%d %s\n", intmet[i], (LPSTR) metname[i] );
  lstrcat( Buff, (LPSTR) auxstr );
 }
}

int WriteTop( LPSTR FName )
{
 GLOBALHANDLE hBuff;
 HCURSOR hSaveCursor;
 LPSTR Buff;
 int ch1, i, udt;
 WORD bufsize;
 OFSTRUCT OfStruct;

 /* display the wait cursor											*/
 hSaveCursor = SetCursor(hHourGlass);

 /* set the maximum buffer size for the topology w/o user-def kin		*/
 bufsize = (WORD) (20 + 256 + 2 + 5 + 2 +
                   totmet*(nsteps*3 + 2) +
                   nsteps*(5 + NAME_L + 2) +
                   nsteps*(MAX_MOL*4 + 2) +
                   nsteps*(totmet*4 + 2) +
                   totmet*(NAME_L + 2 + 2)
                  );
 hBuff = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, bufsize );
 Buff = (LPSTR) GlobalLock( hBuff );
 /* write the information on the buffer									*/
 TopToBuf( Buff );
 /* open the file														*/
 if( (ch1 = OpenFile( FName, &OfStruct, OF_CREATE | OF_WRITE )) != -1 )
 {
  /* write the buffer to the file and close it							*/
  _lwrite( ch1, Buff, (WORD) lstrlen( Buff ) );
  ch1 = _lclose( ch1 );
 }
 if( ch1 == -1 )
 {
  GlobalUnlock( hBuff );
  GlobalFree( hBuff );
  SetCursor(hSaveCursor);
  return IDS_ERR_SAVE;
 }
 /* check if model contains user-defined kinetic types					*/
 for( i=0, udt=0; i<nsteps; i++ )
  if( kinetu[i] >= MAX_TYP )
  {
   udt = 1;
   kfl[i] = 0;
  }
 /* if there are any, output them to the file							*/
 if( udt )
 {
  /* reallocate Buff to accomodate one function							*/
  udt = GlobalUnlock( hBuff );
  hBuff = GlobalReAlloc( hBuff, (WORD) 5500 , GMEM_ZEROINIT | GMEM_MOVEABLE );
  Buff = (LPSTR) GlobalLock( hBuff );
  for( i=0; i<nsteps; i++ )
   if( kinetu[i] >= MAX_TYP )
   {
    /* write the tree function to the buffer							*/
    TreeToBuf( kinetu[i]-MAX_TYP, (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							*/

⌨️ 快捷键说明

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