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

📄 iosim.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
*/

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


#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <io.h>
#include <sys\types.h>
#include <sys\stat.h>
#include "commdlg.h"
#include "globals.h"
#include "iotop.h"
#include "iosim.h"
#include "gep2.h"
#include "simgvar.h"
#include "gaussw.h"
#include "strtbl.h"

#pragma alloc_text( CODE13, TopIn, SimToBuf, WriteSim, BufToSim, ReadSim, setdb )

/*
	set up several database variables
*/
int setdb( int swapnames )
{
 /* set up the strings describing each step							*/
 step_string( );

 /* reduce the stoicheiometry matrix								*/
 if( reduce( swapnames ) != 0 )
  return -1;

 /* if there are no steps with internal metabolites signal and stop	*/
 if( (!nsteps) || (!nmetab) )
  return IDS_ERR_BAD_EMPTY;
 /* setup the parameters structure									*/
 if( SetParams() == -1 )
  return IDS_ERR_NOEXEC;

 /* setup the outpel structure										*/
 if( SetOutpEl() == -1 )
  return IDS_ERR_NOEXEC;

 return 0;
}

/*
	read topology file with validity check
*/

int TopIn( LPSTR tname )
{
 unsigned char  nmod;
 BOOL			badtop;
 int			i, j, nRc;

 if( !(nRc = ReadTop( tname ) ) )
 {
  badtop = FALSE;
  if( (nsteps<=0) || (nsteps>MAX_STEP) ||
      (totmet<=0) || (totmet>MAX_MET)    )
   badtop = TRUE;
  /* check if topology is complete							*/
  for( i=0; i<nsteps; i++ )
  {
   if( kinetu[i]==NOT ) badtop = TRUE;
   if( ktype[kinetu[i]].nmodf > 0 )
   {
    /* count the number of assigned modfs for each reaction	*/
    for( j=0, nmod=0; j<totmet; j++ )
     if( (*loop)[i][j] != 0 ) nmod++;
    if( ktype[kinetu[i]].nmodf != nmod ) badtop = TRUE;
   }
  }

  /* if topology is incomplete, signal and return				*/
  if( badtop )
  {
   tname[0] = '\0';
   return IDS_ERR_BAD_TOP;
  }

  nRc = setdb( 1 ); /* 1 means swap metabolite and step names	*/

  /* exit and signal no errors								*/
  return nRc;
 }
 else return IDS_ERR_LOAD;
}

/*
	write simulation parameters to file
*/

void SimToBuf( LPSTR Buff, LPSTR FName )
{
 int i, j;
 char *p;
 char auxstr[260];

 /* write the kinetic constants, one line per step						*/
 for( i=0; i<nsteps; i++ )
 {
  for( j=0; j<(int)ktype[kinetu[i]].nconst; j++ )
  {
   lstrcat( Buff, (LPSTR) " " );
   gcvt( *(params[i]+j), 20, auxstr );
   lstrcat( Buff, (LPSTR) auxstr );
  }
  lstrcat( Buff, (LPSTR) "\n" );
 }

 /* write the concentrations, one per line								*/
 for( i=0; i<totmet; i++ )
 {
  gcvt( xu[i], 20, auxstr );
  lstrcat( Buff, (LPSTR) auxstr );
  lstrcat( Buff, (LPSTR) "\n" );
 }

 /* write the units in one  line										*/
 wsprintf( (LPSTR) auxstr, "%s %s\n", (LPSTR) options.concu, (LPSTR) options.timeu );
 lstrcat( Buff, (LPSTR) auxstr );
 /* write log, dyn and ss options in one line							*/
 sprintf( auxstr, "%d %d %lu %.20le %.20le %.20le %.20le %d %d %d\n",
          options.debug, options.dyn, options.pfo, options.endtime,
          options.reltol, options.abstol, options.hrcz, options.adams,
          options.bdf, options.ss);
 lstrcat( Buff, (LPSTR) auxstr );
 /* write txt options in one line										*/
 sprintf( auxstr, "%d %d %d %d %d %d %d\n", options.txt,
          options.structan, options.staban, options.stdela,
          options.nonela, options.stdcc, options.noncc );
 lstrcat( Buff, (LPSTR) auxstr );
 /* write the dat options in one line									*/
 sprintf( auxstr, "%d %d %d %d %d %d %d %d %d\n", options.dat, options.datsep,
          options.datwidth, options.dattit, options.datmca, options.datss,
          totsel, options.append, options.quotes );
 lstrcat( Buff, (LPSTR) auxstr );
 /* write the dat file title											*/
 sprintf( auxstr, "%s\n", DatName );
 lstrcat( Buff, (LPSTR) auxstr );
 /* write each output item in one line (index and title)                */
 for( i=0; i<totsel; i++ )
  for( j=0; j<noutpel; j++ )
   if( outpel[j].idx == (unsigned int) (i+1) )
   {
    wsprintf( (LPSTR) auxstr, "%d %s\n", j, outpel[j].title );
    lstrcat( Buff, (LPSTR) auxstr );
   }
 /* write the scan options in one line									*/
 sprintf( auxstr, "%d %lu %d %d %d\n", options.scan, options.scandens,
          options.scanlog, totscan, nlinks );
 lstrcat( Buff, (LPSTR) auxstr );
 /* write each scan item in one line  					                */
 for( i=0; i<totscan; i++ )
  for( j=0; j<nscanpar; j++ )
   if( spar[j].idx == (i+1) )
   {
    sprintf( auxstr, "%d %.20le %.20le %lu %d\n", j, spar[j].low,
             spar[j].high, spar[j].dens, spar[j].log );
    lstrcat( Buff, (LPSTR) auxstr );
   }
 /* write each linked item in one line									*/
 for( i=0; i<nlinks; i++ )
  for( j=0; j<nscanpar; j++ )
   if( spar[j].lidx == i )
   {
    sprintf( auxstr, "%d %d %d %20le\n", j, spar[j].linkedto,
             spar[j].operation, spar[j].factor );
    lstrcat( Buff, (LPSTR) auxstr );
   }
}


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

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

 /*bufsize = (WORD) (3*nsteps + (8*nsteps + 6 + NAME_L)*totmet);		*/
 bufsize = (WORD) 10240;
 hBuff = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT , bufsize );
 Buff = GlobalLock( hBuff );
 /* write the information on the buffer									*/
 TopToBuf( Buff );
 if( (ch1 = OpenFile( FName, &OfStruct, OF_CREATE | OF_WRITE )) != -1 )
 {
  /* write the buffer to the file and close it							*/
  _lwrite( ch1, (LPSTR) Buff, (WORD) lstrlen( Buff ) );
  ch1 = _lclose( ch1 );
 }
 if( ch1 == -1 )
 {
  GlobalUnlock( hBuff );
  GlobalFree( hBuff );
  SetCursor(hSaveCursor);
  return IDS_ERR_SAVE;
 }

 /* set the flags, meaning 'kinetic type not saved' */
 for( i=0; i<nsteps; i++ ) kfl[i] = 1;
 /* check if model contains user-defined kinetic types					*/
 if( nudf>0 )
 {
  for( i=0; i<nsteps; i++ )
   if( (kinetu[i] > MAX_TYP-1) && (kfl[i]) )
   {
    /* 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							*/
     _lseek( ch1, (LONG) 0, 2 );
     _lwrite( ch1, (LPSTR) Buff, (WORD) lstrlen( Buff ) );
     ch1 = _lclose( ch1 );
    }
    if( ch1 == -1 )
    {
     GlobalUnlock( hBuff );
     GlobalFree( hBuff );
     SetCursor(hSaveCursor);
     return IDS_ERR_SAVE;
    }
    /* mark all other reactions with this type */
    for( j=i; j<nsteps; j++ ) if(kinetu[j]==kinetu[i]) kfl[j] = 0;
   }
 }


 Buff[0] = '\0';
 SimToBuf( Buff, FName );
 /* append buffer to  the file											*/
 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) lstrlen( Buff ) );
   ch1 = _lclose( ch1 );
 }
 if( ch1 == -1 )
 {
  GlobalUnlock( hBuff );
  GlobalFree( hBuff );
  SetCursor(hSaveCursor);
  return IDS_ERR_SAVE;
 }

 /* release the memory block											*/
 GlobalUnlock( hBuff );
 GlobalFree( hBuff );
 SetCursor(hSaveCursor);

⌨️ 快捷键说明

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