home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / biology / gsrc208a.zip / GEP2.C < prev    next >
C/C++ Source or Header  |  1993-07-07  |  35KB  |  1,131 lines

  1. #include "copyleft.h"
  2.  
  3. /*
  4.     GEPASI - a simulator of metabolic pathways and other dynamical systems
  5.     Copyright (C) 1989, 1992, 1993  Pedro Mendes
  6. */
  7.  
  8. /*************************************/
  9. /*                                   */
  10. /*         GWSIM - Simulation        */
  11. /*        MS-WINDOWS front end       */
  12. /*                                   */
  13. /*       Initialization and some     */
  14. /*           data structures         */
  15. /*                                   */
  16. /*           QuickC/WIN 1.0          */
  17. /*                                   */
  18. /*   (include here compilers that    */
  19. /*   compiled GWSIM successfully)    */
  20. /*                                   */
  21. /*************************************/
  22.  
  23.  
  24. #include <windows.h>
  25. #include <string.h>
  26. #include <float.h>
  27. #include "globals.h"
  28. #include "gaussw.h"
  29. #include "strtbl.h"
  30. #include "simgvar.h"
  31.  
  32. void get_dfts( void );
  33.  
  34. struct kint {
  35.                   unsigned char nconst;
  36.                   unsigned char nmodf;
  37.                   LPSTR descr;
  38.                 LPSTR constnam;
  39.                };
  40.  
  41. struct nodet{
  42.              char item;
  43.              unsigned char val;
  44.              unsigned char left;
  45.              unsigned char right;
  46.             };
  47.  
  48. struct treet{
  49.              struct nodet node[256];
  50.              char id[64][10];
  51.              float constant[32];
  52.              int nnode,
  53.                  nnum,
  54.                  nid,
  55.                  nsub,
  56.                  npro,
  57.                  nmodf,
  58.                  nconst,
  59.                  revers;
  60.              char descr[64];
  61.             };
  62.  
  63. struct opt {
  64.             int dyn;
  65.             long pfo;
  66.             double    endtime;
  67.             double    reltol;
  68.             double    abstol;
  69.             double    hrcz;
  70.             int adams;
  71.             int bdf;
  72.             int ss;
  73.             int debug;
  74.             int txt;
  75.             int structan;
  76.             int staban;
  77.             int stdela;
  78.             int nonela;
  79.             int stdcc;
  80.             int noncc;
  81.             int dat;
  82.             int datsep;
  83.             int datwidth;
  84.             int dattit;
  85.             int datmca;
  86.             int datss;
  87.             int quotes;
  88.             int append;
  89.             char timeu[32];
  90.             char concu[32];
  91.             int scan;
  92.             int scanlog;
  93.             unsigned long scandens;
  94.            };
  95.  
  96. struct plt{
  97.            int type;        /* 0 for 2d, 1 for 3d */
  98.            int file;        /* 0 for dynamics, 1 for steady state */
  99.            int x;            /* column for x */
  100.            int y[10];        /* columns for y */
  101.            int z;            /* column for z */
  102.            int ny;            /* number of y variables */
  103.            int logx;        /* 1 if log x axis */
  104.            int logy;        /* 1 if log y axis */
  105.            int logz;        /* 1 if log z axis */
  106.            int lines;        /* 1 if points connected by lines */
  107.            int colour;        /* 1 if colour to be used */
  108.            int hidden;        /* 1 if hidden line removal */
  109.            int contour;        /* 1 if contour plots on base */
  110.           };
  111.  
  112. struct ou {
  113.            LPSTR title;
  114.            unsigned int idx;
  115.           };
  116.  
  117. struct sp{
  118.           int idx;
  119.           LPSTR title;
  120.           double low;
  121.           double high;
  122.           unsigned long dens;
  123.           int log;
  124.           int lidx;
  125.           int linkedto;
  126.           double factor;
  127.           int operation;
  128.          };
  129.  
  130. GLOBALHANDLE hMetname;                                /* handle to memory block w/ metname    */
  131. GLOBALHANDLE hStepname;                                /* handle to memory block w/ stepname    */
  132. GLOBALHANDLE hStoiu;                                /* handle to memory block w/ stoiu        */
  133. GLOBALHANDLE hSto;                                    /* handle to memory block w/ stoi        */
  134. GLOBALHANDLE hLoop;                                    /* handle to memory block w/ loop        */
  135. GLOBALHANDLE hParams;                                /* handle to memory block w/ params        */
  136. GLOBALHANDLE hKtype;                                /* handle to memory block w/ ktype        */
  137. GLOBALHANDLE hRstr;                                    /* handle to memory block w/ rstr        */
  138. GLOBALHANDLE hOutpEl;                                /* handle to memory block w/ outpel        */
  139. GLOBALHANDLE hStrPool;                                /* handle to memory block w/ strings    */
  140. GLOBALHANDLE hScanPar;                                /* handle to memory block w/ strings    */
  141. GLOBALHANDLE hTree;                                    /* handle to memory block w/ trees        */
  142. GLOBALHANDLE hTreeStr;                                /* handle to memory block w/ tree str    */
  143. GLOBALHANDLE hTmpF;                                    /* handle to memory block w/ temp files    */
  144.  
  145. char    (huge *metname)[NAME_L];                    /* pointer to work with metname array    */
  146. char    (huge *stepname)[NAME_L];                    /* metabolite names                        */
  147. int        huge *stoiu;                                /* pointer to work with stoiu array        */
  148. int        huge *stoi;                                    /* pointer to work with stoi array        */
  149. unsigned char (huge *loop)[MAX_STEP][MAX_MET];        /* def. of modification loops            */
  150. int        (huge *rstr)[MAX_STEP][MAX_MOL];            /* reaction structure                    */
  151. char    topname[256];                                /* title for the topology                */
  152. char    stepstr[MAX_STEP][256];                        /* array to hold description of steps    */
  153. double     huge *params[MAX_STEP];                        /* ptr to parameters for each rate eq.    */
  154. DWORD    sizeparam;                                    /* size of parameters memory block        */
  155. DWORD    sizeoutp;                                    /* size of outpel memory block            */
  156. DWORD    sizestrp;                                    /* size of StrPool memory block            */
  157. DWORD    sizestra;                                    /* size of allocated strings in StrPool    */
  158. DWORD    sizespar;
  159. DWORD    sizetr;                                        /* size of allocated strings in TreeStr    */
  160. double    xu[MAX_MET];                                /* metabolite concentrations            */
  161. double    moiety[MAX_MET];                            /* concentration of conserved moieties    */
  162. int        intmet[MAX_MET];                            /* 1 if internal metabolite                */
  163. unsigned char    revers[MAX_STEP];                    /* 1 if reaction is reversible            */
  164. int        kinetu[MAX_STEP];                            /* type of kinetics (user numb.)        */
  165. int        kfl[MAX_STEP];                                /* flags for input of user-def.kinetics */
  166. LPSTR    strpool;                                    /* points to the string pool mem block    */
  167. LPSTR    treestr;                                    /* points to the tree string pool        */
  168. LPSTR    treeptr;                                    /* points to the tree string pool        */
  169. struct    opt options;                                /* structure with simulation options    */
  170. struct    plt plot;                                    /* structure with plot options            */
  171. struct    kint huge *ktype;                            /* ptr array of kinetic types & proprt    */
  172. struct    ou huge *outpel;                            /* ptr array of output elements            */
  173. struct    sp huge *spar;                                /* ptr array of scanning elements        */
  174. float    ver_no;                                        /* .top and .sim version number            */
  175. double    dft_endtime;                                /* time value for last iteration        */
  176. double    dft_hrcz;                                    /* highest rate considered zero            */
  177. int        totmet;                                        /* number of total metabolites            */
  178. int        nmetab;                                        /* number of internal metabolites        */
  179. int        indmet;                                        /* number of independent metabolites    */
  180. int        nextmet;                                    /* number of external metabolites        */
  181. int        nsteps;                                        /* number of steps                        */
  182. int        nloops;                                        /* number of modifier loops             */
  183. int        noutpel;                                    /* number of output elements            */
  184. int        nudf;                                        /* number of user-defined functions        */
  185. int        nrateq;                                        /* number of user-defined functions        */
  186. int        totsel;                                     /* number of selected output elements    */
  187. int        totscan;                                    /* number of dimensions to scan            */
  188. int        nscanpar;                                   /* number of scanning elements            */
  189. int        nlinks;                                        /* number of links between parameters    */
  190. unsigned char dft_debugval;                            /* debug mode                            */
  191. double    dft_conc;                                    /* default metabolite concentration        */
  192. double    dft_const;                                    /* default value for kinetic constants    */
  193. char    *dft_timeu;                                    /* default time units                    */
  194. char    *dft_concu;                                    /* default conctration units            */
  195. unsigned long dft_pfo;                                /* number of points for output            */
  196. struct    treet huge *tree;                            /* function tree for rate equations        */
  197. struct    treet tr;                                    /* tree for the input                    */
  198. LPSTR    TmpFiles;                                    /* string holding names of temp files    */
  199.  
  200. int        InitGepasiVar( void );
  201. void    TidyGepasiVar( void );
  202. int     SetParams( void );
  203. int     SetOutpEl( void );
  204. void     step_string( void );
  205. void    conc_dft( void );
  206. void     numer_dft( void );
  207. void     def_def( void );
  208. void     set_dfts( void );
  209. void     get_dfts( void );
  210.  
  211. #pragma alloc_text( CODE1, InitGepasiVar, TidyGepasiVar, SetParams, SetOutpEl, step_string, conc_dft, numer_dft, def_def, set_dfts, get_dfts )
  212.  
  213. /* Initialization of GEPASI's variables */
  214.  
  215. int InitGepasiVar( void )
  216. {
  217.  int i, j;
  218.  
  219.  hMetname = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) MAX_MET * NAME_L * sizeof( char ) );
  220.  if( hMetname == NULL ) return -1;
  221.  
  222.  hStepname = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) MAX_STEP * NAME_L * sizeof( char ) );
  223.  if( hStepname == NULL )
  224.  {
  225.   GlobalFree( hMetname );
  226.   return -1;
  227.  }
  228.  
  229.  hStoiu = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) MAX_MET * MAX_STEP * sizeof( int ) );
  230.  if( hStoiu == NULL )
  231.  {
  232.   GlobalFree( hMetname );
  233.   GlobalFree( hStepname );
  234.   return -1;
  235.  }
  236.  
  237.  hLoop = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) MAX_STEP * MAX_MET * sizeof( unsigned char ) );
  238.  if( hLoop == NULL )
  239.  {
  240.   GlobalFree( hMetname );
  241.   GlobalFree( hStepname );
  242.   GlobalFree( hStoiu );
  243.   return -1;
  244.  }
  245.  
  246.  hKtype = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) MAX_TYP * sizeof( struct kint ) );
  247.  if( hKtype == NULL )
  248.  {
  249.   GlobalFree( hMetname );
  250.   GlobalFree( hStepname );
  251.   GlobalFree( hStoiu );
  252.   GlobalFree( hLoop );
  253.   return -1;
  254.  }
  255.  
  256.  hRstr = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) MAX_STEP * MAX_MOL * sizeof( int ) );
  257.  if( hRstr == NULL )
  258.  {
  259.   GlobalFree( hMetname );
  260.   GlobalFree( hStepname );
  261.   GlobalFree( hStoiu );
  262.   GlobalFree( hLoop );
  263.   GlobalFree( hKtype );
  264.   return -1;
  265.  }
  266.  
  267.  sizeparam = (DWORD) sizeof( double );
  268.  hParams = GlobalAlloc( GMEM_ZEROINIT, sizeparam );
  269.  if( hParams == NULL )
  270.  {
  271.   GlobalFree( hMetname );
  272.   GlobalFree( hStepname );
  273.   GlobalFree( hStoiu );
  274.   GlobalFree( hLoop );
  275.   GlobalFree( hKtype );
  276.   GlobalFree( hRstr );
  277.   return -1;
  278.  }
  279.  
  280.  sizeoutp = (DWORD) 4 * sizeof( struct ou );
  281.  hOutpEl = GlobalAlloc( GMEM_ZEROINIT, sizeoutp );
  282.  if( hOutpEl == NULL )
  283.  {
  284.   GlobalFree( hMetname );
  285.   GlobalFree( hStepname );
  286.   GlobalFree( hStoiu );
  287.   GlobalFree( hLoop );
  288.   GlobalFree( hKtype );
  289.   GlobalFree( hRstr );
  290.   GlobalFree( hParams );
  291.   return -1;
  292.  }
  293.  
  294.  sizestrp = (DWORD) 4 * 17; /* strings will be limited to 17, but this can change */
  295.  hStrPool = GlobalAlloc( GMEM_ZEROINIT, sizestrp );
  296.  if( hStrPool == NULL )
  297.  {
  298.   GlobalFree( hMetname );
  299.   GlobalFree( hStepname );
  300.   GlobalFree( hStoiu );
  301.   GlobalFree( hLoop );
  302.   GlobalFree( hKtype );
  303.   GlobalFree( hRstr );
  304.   GlobalFree( hParams );
  305.   GlobalFree( hOutpEl );
  306.   return -1;
  307.  }
  308.  
  309.  sizespar = (DWORD) 4 * sizeof( struct sp );
  310.  hScanPar = GlobalAlloc( GMEM_ZEROINIT, sizespar );
  311.  if( hScanPar == NULL )
  312.  {
  313.   GlobalFree( hMetname );
  314.   GlobalFree( hStepname );
  315.   GlobalFree( hStoiu );
  316.   GlobalFree( hLoop );
  317.   GlobalFree( hKtype );
  318.   GlobalFree( hRstr );
  319.   GlobalFree( hParams );
  320.   GlobalFree( hOutpEl );
  321.   GlobalFree( hStrPool );
  322.   return -1;
  323.  }
  324.  
  325.  hSto = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) MAX_MET * MAX_STEP * sizeof( int ) );
  326.  if( hSto == NULL )
  327.  {
  328.   GlobalFree( hMetname );
  329.   GlobalFree( hStepname );
  330.   GlobalFree( hStoiu );
  331.   GlobalFree( hLoop );
  332.   GlobalFree( hKtype );
  333.   GlobalFree( hRstr );
  334.   GlobalFree( hParams );
  335.   GlobalFree( hOutpEl );
  336.   GlobalFree( hStrPool );
  337.   GlobalFree( hScanPar );
  338.   return -1;
  339.  }
  340.  
  341.  sizetr = (DWORD) 4 * sizeof( char );
  342.  hTreeStr = GlobalAlloc( GMEM_ZEROINIT, sizetr );
  343.  if( hTreeStr == NULL )
  344.  {
  345.   GlobalFree( hMetname );
  346.   GlobalFree( hStepname );
  347.   GlobalFree( hStoiu );
  348.   GlobalFree( hLoop );
  349.   GlobalFree( hKtype );
  350.   GlobalFree( hRstr );
  351.   GlobalFree( hParams );
  352.   GlobalFree( hOutpEl );
  353.   GlobalFree( hStrPool );
  354.   GlobalFree( hScanPar );
  355.   GlobalFree( hSto );
  356.   return -1;
  357.  }
  358.  
  359.  nudf = 0;
  360.  hTree = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) sizeof( struct treet ) );
  361.  if( hTree == NULL )
  362.  {
  363.   GlobalFree( hMetname );
  364.   GlobalFree( hStepname );
  365.   GlobalFree( hStoiu );
  366.   GlobalFree( hLoop );
  367.   GlobalFree( hKtype );
  368.   GlobalFree( hRstr );
  369.   GlobalFree( hParams );
  370.   GlobalFree( hOutpEl );
  371.   GlobalFree( hStrPool );
  372.   GlobalFree( hScanPar );
  373.   GlobalFree( hSto );
  374.   GlobalFree( hTreeStr );
  375.   return -1;
  376.  }
  377.  
  378.  /* allocate memory to hold the names of the temp files    */
  379.  hTmpF = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) 2 );
  380.  if( hTmpF == NULL )
  381.  {
  382.   GlobalFree( hMetname );
  383.   GlobalFree( hStepname );
  384.   GlobalFree( hStoiu );
  385.   GlobalFree( hLoop );
  386.   GlobalFree( hKtype );
  387.   GlobalFree( hRstr );
  388.   GlobalFree( hParams );
  389.   GlobalFree( hOutpEl );
  390.   GlobalFree( hStrPool );
  391.   GlobalFree( hScanPar );
  392.   GlobalFree( hSto );
  393.   GlobalFree( hTreeStr );
  394.   GlobalFree( hTree );
  395.   return -1;
  396.  }
  397.  
  398.  metname    = ( char (huge *)[NAME_L] ) GlobalLock( hMetname );
  399.  stepname    = ( char (huge *)[NAME_L] ) GlobalLock( hStepname );
  400.  stoiu        = ( int huge * ) GlobalLock( hStoiu );
  401.  loop        = ( unsigned char (huge *)[MAX_STEP][MAX_MET] ) GlobalLock( hLoop );
  402.  ktype        = ( struct kint huge * ) GlobalLock( hKtype );
  403.  rstr        = ( int (huge *)[MAX_STEP][MAX_MOL] ) GlobalLock( hRstr );
  404.  params[0]    = (double huge *) GlobalLock( hParams );
  405.  outpel        = ( struct ou huge * ) GlobalLock( hOutpEl );
  406.  spar        = ( struct sp huge * ) GlobalLock( hScanPar );
  407.  strpool    = GlobalLock( hStrPool );
  408.  stoi        = (int huge *) GlobalLock( hSto );
  409.  treestr    = GlobalLock( hTreeStr );
  410.  tree        = ( struct treet huge * ) GlobalLock( hTree );
  411.  TmpFiles    = (LPSTR) GlobalLock( hTmpF );
  412.  
  413.  *TmpFiles = '\0';
  414.  
  415.  /* make the other params[i] point to NULL                                            */
  416.  for( i=1; i<MAX_STEP; i++ ) params[i] = NULL;
  417.  
  418.  get_dfts();                                        /* read GEPASI default values    */
  419.  totmet = nmetab = nsteps = 0;                        /* clear no. of metb. and steps    */
  420.  
  421.  nrateq = MAX_TYP;
  422.  
  423.  ktype[NOT].nconst = 0;
  424.  ktype[NOT].nmodf = 0;
  425.  ktype[NOT].constnam = (LPSTR) "";
  426.  ktype[NOT].descr = (LPSTR) "<not defined>";
  427.  ktype[I01].nconst = 1;
  428.  ktype[I01].nmodf = 0;
  429.  ktype[I01].constnam = (LPSTR) "k";
  430.  ktype[I01].descr = (LPSTR) "constant rate";
  431.  ktype[I10].nconst = 1;
  432.  ktype[I10].nmodf = 0;
  433.  ktype[I10].constnam = (LPSTR) "k";
  434.  ktype[I10].descr = (LPSTR) ktype[I01].descr;
  435.  ktype[I11].nconst = 1;
  436.  ktype[I11].nmodf = 0;
  437.  ktype[I11].constnam = (LPSTR) "k";
  438.  ktype[I11].descr = (LPSTR) "mass action";
  439.  ktype[R11].nconst = 2;
  440.  ktype[R11].nmodf = 0;
  441.  ktype[R11].constnam = (LPSTR) "k1\0k2";
  442.  ktype[R11].descr = (LPSTR) ktype[I11].descr;
  443.  ktype[I21].nconst = 1;
  444.  ktype[I21].nmodf = 0;
  445.  ktype[I21].constnam = (LPSTR) ktype[I11].constnam;
  446.  ktype[I21].descr = (LPSTR) ktype[I11].descr;
  447.  ktype[R21].nconst = 2;
  448.  ktype[R21].nmodf = 0;
  449.  ktype[R21].constnam = (LPSTR) ktype[R11].constnam;
  450.  ktype[R21].descr = (LPSTR) ktype[I11].descr;
  451.  ktype[I12].nconst = 1;
  452.  ktype[I12].nmodf = 0;
  453.  ktype[I12].constnam = (LPSTR) ktype[I11].constnam;
  454.  ktype[I12].descr = (LPSTR) ktype[I11].descr;
  455.  ktype[R12].nconst = 2;
  456.  ktype[R12].nmodf = 0;
  457.  ktype[R12].constnam = (LPSTR) ktype[R11].constnam;
  458.  ktype[R12].descr = (LPSTR) ktype[I11].descr;
  459.  ktype[I31].nconst = 1;
  460.  ktype[I31].nmodf = 0;
  461.  ktype[I31].constnam = (LPSTR) ktype[I11].constnam;
  462.  ktype[I31].descr = (LPSTR) ktype[I11].descr;
  463.  ktype[R31].nconst = 2;
  464.  ktype[R31].nmodf = 0;
  465.  ktype[R31].constnam = (LPSTR) ktype[R11].constnam;
  466.  ktype[R31].descr = (LPSTR) ktype[I11].descr;
  467.  ktype[I13].nconst = 1;
  468.  ktype[I13].nmodf = 0;
  469.  ktype[I13].constnam = (LPSTR) ktype[I11].constnam;
  470.  ktype[I13].descr = (LPSTR) ktype[I11].descr;
  471.  ktype[R13].nconst = 2;
  472.  ktype[R13].nmodf = 0;
  473.  ktype[R13].constnam = (LPSTR) ktype[R11].constnam;
  474.  ktype[R13].descr = (LPSTR) ktype[I11].descr;
  475.  ktype[I22].nconst = 1;
  476.  ktype[I22].nmodf = 0;
  477.  ktype[I22].constnam = (LPSTR) ktype[I11].constnam;
  478.  ktype[I22].descr = (LPSTR) ktype[I11].descr;
  479.  ktype[R22].nconst = 2;
  480.  ktype[R22].nmodf = 0;
  481.  ktype[R22].constnam = (LPSTR) ktype[R11].constnam;
  482.  ktype[R22].descr = (LPSTR) ktype[I11].descr;
  483.  ktype[I32].nconst = 1;
  484.  ktype[I32].nmodf = 0;
  485.  ktype[I32].constnam = (LPSTR) ktype[I11].constnam;
  486.  ktype[I32].descr = (LPSTR) ktype[I11].descr;
  487.  ktype[R32].nconst = 2;
  488.  ktype[R32].nmodf = 0;
  489.  ktype[R32].constnam = (LPSTR) ktype[R11].constnam;
  490.  ktype[R32].descr = (LPSTR) ktype[I11].descr;
  491.  ktype[I23].nconst = 1;
  492.  ktype[I23].nmodf = 0;
  493.  ktype[I23].constnam = (LPSTR) ktype[I11].constnam;
  494.  ktype[I23].descr = (LPSTR) ktype[I11].descr;
  495.  ktype[R23].nconst = 2;
  496.  ktype[R23].nmodf = 0;
  497.  ktype[R23].constnam = (LPSTR) ktype[R11].constnam;
  498.  ktype[R23].descr = (LPSTR) ktype[I11].descr;
  499.  ktype[I33].nconst = 1;
  500.  ktype[I33].nmodf = 0;
  501.  ktype[I33].constnam = (LPSTR) ktype[I11].constnam;
  502.  ktype[I33].descr = (LPSTR) ktype[I11].descr;
  503.  ktype[R33].nconst = 2;
  504.  ktype[R33].nmodf = 0;
  505.  ktype[R33].constnam = (LPSTR) ktype[R11].constnam;
  506.  ktype[R33].descr = (LPSTR) ktype[I11].descr;
  507.  ktype[IMM].nconst = 2;
  508.  ktype[IMM].nmodf = 0;
  509.  ktype[IMM].constnam = (LPSTR) "Km\0V";
  510.  ktype[IMM].descr = (LPSTR) "Michaelis-Menten";
  511.  ktype[RMM].nconst = 4;
  512.  ktype[RMM].nmodf = 0;
  513.  ktype[RMM].constnam = (LPSTR) "Kms\0Kmp\0Vf\0Vr";
  514.  ktype[RMM].descr = (LPSTR) "Reversible Michaelis-Menten";
  515.  ktype[PSI].nconst = 5;
  516.  ktype[PSI].nmodf = 1;
  517.  ktype[PSI].constnam = (LPSTR) "Kms\0Kmp\0Vf\0Vr\0Ki";
  518.  ktype[PSI].descr = (LPSTR) "specific inhibition";
  519.  ktype[PCI].nconst = 5;
  520.  ktype[PCI].nmodf = 1;
  521.  ktype[PCI].constnam = ktype[PSI].constnam;
  522.  ktype[PCI].descr = (LPSTR) "catalytic inhibition";
  523.  ktype[MXI].nconst = 6;
  524.  ktype[MXI].nmodf = 1;
  525.  ktype[MXI].constnam = (LPSTR) "Kms\0Kmp\0Vf\0Vr\0Ki\0Ki'";
  526.  ktype[MXI].descr = (LPSTR) "mixed inhibition";
  527.  ktype[PSA].nconst = 5;
  528.  ktype[PSA].nmodf = 1;
  529.  ktype[PSA].constnam = (LPSTR) "Kms\0Kmp\0Vf\0Vr\0Ka";
  530.  ktype[PSA].descr = (LPSTR) "specific activation";
  531.  ktype[PCA].nconst = 5;
  532.  ktype[PCA].nmodf = 1;
  533.  ktype[PCA].constnam = ktype[PSA].constnam;
  534.  ktype[PCA].descr = (LPSTR) "catalytic activation";
  535.  ktype[MXA].nconst = 6;
  536.  ktype[MXA].nmodf = 1;
  537.  ktype[MXA].constnam = (LPSTR) "Kms\0Kmp\0Vf\0Vr\0Ka\0Ka'";
  538.  ktype[MXA].descr = (LPSTR) "mixed activation";
  539.  ktype[GOM].nconst = 6;
  540.  ktype[GOM].nmodf = 1;
  541.  ktype[GOM].constnam = (LPSTR) "Kms\0Kmp\0Vf\0Vr\0Ki\0Ki'";
  542.  ktype[GOM].descr = (LPSTR) "Botts-Morales";
  543.  ktype[HIL].nconst = 3;
  544.  ktype[HIL].nmodf = 0;
  545.  ktype[HIL].constnam = (LPSTR) "K\0V\0h";
  546.  ktype[HIL].descr = (LPSTR) "Hill";
  547.  ktype[UBS].nconst = 6;
  548.  ktype[UBS].nmodf = 0;
  549.  ktype[UBS].constnam = (LPSTR) "Ka\0Kp\0Kq\0Kpq\0Vf\0Vr";
  550.  ktype[UBS].descr = (LPSTR) "Ordered Uni Bi (A=P+Q)";
  551.  ktype[UBM].nconst = 4;
  552.  ktype[UBM].nmodf = 0;
  553.  ktype[UBM].constnam = (LPSTR) "Ka\0Kp\0Vf\0Vr";
  554.  ktype[UBM].descr = (LPSTR) "Ordered Uni Bi (A=2*P)";
  555.  ktype[RHL].nconst = 6;
  556.  ktype[RHL].nmodf = 0;
  557.  ktype[RHL].constnam = (LPSTR) "Kms\0Kmp\0Vf\0Vr\0hs\0hp";
  558.  ktype[RHL].descr = (LPSTR) "Reversible Hill";
  559.  ktype[ALI].nconst = 6;
  560.  ktype[ALI].nmodf = 1;
  561.  ktype[ALI].constnam = (LPSTR) "Kms\0Kmp\0Vf\0Vr\0Ki\0h";
  562.  ktype[ALI].descr = (LPSTR) "Allosteric inhibition";
  563.  
  564.  nudf = 0;
  565.  return 0;
  566. }
  567.  
  568. /*
  569.     set up the pointers to params
  570. */
  571.  
  572. int SetParams( void )
  573. {
  574.  int i, j;
  575.  
  576.  /* calculate the size of parameters array                */
  577.  for( i=0, j=0; i<nsteps; i++ )
  578.   j += ktype[kinetu[i]].nconst;
  579.  
  580.  /* unlock hParams to be able to ReAlloc it                */
  581.  GlobalUnlock( hParams );
  582.  
  583.  sizeparam = (DWORD) j * sizeof( double );
  584.  /* reallocate memory for parameters from global heap    */
  585.  hParams = GlobalReAlloc( hParams, sizeparam, GMEM_ZEROINIT | GMEM_MOVEABLE );
  586.  if( hParams == NULL ) return -1;
  587.  
  588.  /* point to the parameters of the first step             */
  589.  params[0] = (double huge *) GlobalLock( hParams );
  590.  /* set all constants of step 0 to the default value    */
  591.  for( j=0; j<(int)ktype[kinetu[0]].nconst; j++ )
  592.   *(params[0]+j) = dft_const;
  593.  
  594.  /* set the other pointers                                */
  595.  for( i=1; i<nsteps; i++ )
  596.  {
  597.   params[i] = params[i-1] + ktype[kinetu[i-1]].nconst;
  598.   /* set all constants of step j to the default value    */
  599.   for( j=0; j<(int)ktype[kinetu[i]].nconst; j++ )
  600.    *(params[i]+j) = dft_const;
  601.  }
  602.  
  603.  return 0;
  604. }
  605.  
  606.  
  607. /*
  608.   setup the output elements
  609. */
  610.  
  611. int SetOutpEl( void )
  612. {
  613.  int i, j, k, l;
  614.  LPSTR ptr, poolptr;
  615.  char buff[128], c;
  616.  
  617.  /* calculate the number of output elements                */
  618.  /* all metabolite concentrations and step fluxes        */
  619.  noutpel = 2*totmet + nsteps;
  620.  nscanpar = totmet;
  621.  /* all kinetic constants...                            */
  622.  for( i=0; i<nsteps; i++ )
  623.  {
  624.   noutpel += ktype[kinetu[i]].nconst;
  625.   nscanpar += ktype[kinetu[i]].nconst;
  626.  }
  627.  /* all elasticies                                        */
  628.  noutpel += nsteps * totmet;
  629.  /* all concentration control coefficients                */
  630.  noutpel += totmet * nsteps;
  631.  /* all flux control coefficients                        */
  632.  noutpel += nsteps * nsteps;
  633.  /* endtime, rel and abs tol, nfunc, njacob, nistep,
  634.     smstep, flux resolution                                */
  635.  noutpel += 8;
  636.  nscanpar += 4;
  637.  
  638.  /* unlock memory blocks to be able to ReAlloc them        */
  639.  GlobalUnlock( hOutpEl );
  640.  GlobalUnlock( hStrPool );
  641.  GlobalUnlock( hScanPar );
  642.  
  643.  sizeoutp = (DWORD) noutpel * sizeof( struct ou );
  644.  sizespar = (DWORD) nscanpar * sizeof( struct sp );
  645.  sizestrp = (DWORD) noutpel * 44;
  646.  
  647.  /* reallocate memory for parameters from global heap    */
  648.  hOutpEl = GlobalReAlloc( hOutpEl, sizeoutp, GMEM_ZEROINIT | GMEM_MOVEABLE );
  649.  if( hOutpEl == NULL )
  650.  {
  651.   return -1;
  652.  }
  653.  hScanPar = GlobalReAlloc( hScanPar, sizespar, GMEM_ZEROINIT | GMEM_MOVEABLE );
  654.  if( hScanPar == NULL )
  655.  {
  656.   return -1;
  657.  }
  658.  hStrPool = GlobalReAlloc( hStrPool, sizestrp, GMEM_ZEROINIT | GMEM_MOVEABLE );
  659.  if( hStrPool == NULL )
  660.  {
  661.   return -1;
  662.  }
  663.  
  664.  /* lock the memory block and have outpel[0] point to it*/
  665.  outpel  = (struct ou huge *) GlobalLock( hOutpEl );
  666.  spar    = (struct sp huge *) GlobalLock( hScanPar );
  667.  strpool = GlobalLock( hStrPool );
  668.  
  669.  /* reset the auxiliary pool pointer                    */
  670.  poolptr = strpool;
  671.  
  672.  /* set all idx to 0 (to signal not selected)            */
  673.  for( i=0; i<noutpel; i++ )
  674.   outpel[i].idx = 0;
  675.  for( i=0; i<nscanpar; i++ )
  676.  {
  677.   spar[i].idx = 0;
  678.   spar[i].low = 0;
  679.   spar[i].high= 0;
  680.   spar[i].dens = (unsigned long) 1;
  681.   spar[i].log = 0;
  682.   spar[i].factor = 1;
  683.   spar[i].operation = 1;
  684.   spar[i].lidx = -1;
  685.   spar[i].linkedto = -1;
  686.  }
  687.  
  688.  /* initialize the titles                                */
  689.  
  690.  /* initial concentrations                                 */
  691.  for( i=0; i<totmet; i++ )
  692.  {
  693.   wsprintf( (LPSTR) buff, "[%s]i", (LPSTR) metname[i] );
  694.   /* copy buff to the string pool                        */
  695.   _fstrcpy( (char __far *) poolptr,
  696.             (char __far *) buff );
  697.  
  698.   /* store the pointer in outpel[i] and spar[i]            */
  699.   outpel[i].title = spar[i].title = poolptr;
  700.  
  701.   /* increase poolptr to point to the first free byte    */
  702.   poolptr += _fstrlen( buff ) + 1;
  703.  }
  704.  l = i;
  705.  
  706.  /* concentrations at time t                            */
  707.  for( j=0; j<totmet; j++, i++ )
  708.  {
  709.   wsprintf( (LPSTR) buff, "[%s]f", (LPSTR) metname[j] );
  710.   /* copy buff to the string pool                        */
  711.   _fstrcpy( (char __far *) poolptr,
  712.             (char __far *) buff );
  713.  
  714.   /* store the pointer in outpel[i] and spar[i]            */
  715.   outpel[i].title = poolptr;
  716.  
  717.   /* increase poolptr to point to the first free byte    */
  718.   poolptr += _fstrlen( buff ) + 1;
  719.  }
  720.  
  721.  for( j=0; j<nsteps; j++, i++ )
  722.  {
  723.   wsprintf( (LPSTR) buff, "J(%s)", (LPSTR) stepname[j] );
  724.   /* copy buff to the string pool                        */
  725.   _fstrcpy( (char __far *) poolptr,
  726.             (char __far *) buff );
  727.  
  728.   /* store the pointer in outpel[i]                        */
  729.   outpel[i].title = poolptr;
  730.  
  731.   /* increase poolptr to point to the first free byte    */
  732.   poolptr += _fstrlen( buff ) + 1;
  733.  }
  734.  
  735.  for( j=0; j<nsteps; j++ )
  736.   for( k=0, ptr = ktype[kinetu[j]].constnam;
  737.        k < (int) ktype[kinetu[j]].nconst;
  738.        k++, i++, l++
  739.      )
  740.   {
  741.    wsprintf( (LPSTR) buff, "%s,%s", (LPSTR) ptr, (LPSTR) stepname[j] );
  742.    /* copy buff to the string pool                        */
  743.    _fstrcpy( (char __far *) poolptr,
  744.              (char __far *) buff );
  745.  
  746.    /* store the pointer in outpel[i]                    */
  747.    outpel[i].title = spar[l].title = poolptr;
  748.  
  749.    /* ptr points to the following constant name            */
  750.    do{} while( *(ptr++) );
  751.  
  752.    /* increase poolptr to point to the first free byte    */
  753.    poolptr += _fstrlen( buff ) + 1;
  754.   }
  755.  
  756.   for( j=0; j<nsteps; j++ )
  757.    for(k=0;k<totmet;k++,i++)
  758.    {
  759.     wsprintf( (LPSTR) buff,"e(%s,[%s])", (LPSTR) stepname[j], (LPSTR) metname[k]);
  760.     /* copy buff to the string pool                        */
  761.     _fstrcpy( (char __far *) poolptr,
  762.               (char __far *) buff );
  763.  
  764.     /* store the pointer in outpel[i]                    */
  765.     outpel[i].title = poolptr;
  766.  
  767.     /* increase poolptr to point to the first free byte    */
  768.     poolptr += _fstrlen( buff ) + 1;
  769.    }
  770.  
  771.   for( j=0; j<totmet; j++ )
  772.    for(k=0;k<nsteps;k++,i++)
  773.    {
  774.     wsprintf( (LPSTR) buff,"C([%s],%s)", (LPSTR) metname[j], (LPSTR) stepname[k]);
  775.     /* copy buff to the string pool                        */
  776.     _fstrcpy( (char __far *) poolptr,
  777.               (char __far *) buff );
  778.  
  779.     /* store the pointer in outpel[i]                    */
  780.     outpel[i].title = poolptr;
  781.  
  782.     /* increase poolptr to point to the first free byte    */
  783.     poolptr += _fstrlen( buff ) + 1;
  784.    }
  785.  
  786.   for( j=0; j<nsteps; j++ )
  787.    for(k=0;k<nsteps;k++,i++)
  788.    {
  789.     wsprintf( (LPSTR) buff,"C(J(%s),%s)", (LPSTR) stepname[j], (LPSTR) stepname[k]);
  790.     /* copy buff to the string pool                        */
  791.     _fstrcpy( (char __far *) poolptr,
  792.               (char __far *) buff );
  793.  
  794.     /* store the pointer in outpel[i]                    */
  795.     outpel[i].title = poolptr;
  796.  
  797.     /* increase poolptr to point to the first free byte    */
  798.     poolptr += _fstrlen( buff ) + 1;
  799.    }
  800.  
  801.   /* endtime, tolerance, nfunc, njacob, nistep, smstep    */
  802.   wsprintf( (LPSTR) buff,"time");
  803.   /* copy buff to the string pool                        */
  804.   _fstrcpy( (char __far *) poolptr,
  805.             (char __far *) buff );
  806.   /* store the pointer in outpel[i]                        */
  807.   outpel[i].title = spar[l].title = poolptr;
  808.   /* increase i                                            */
  809.   i++; l++;
  810.   /* increase poolptr to point to the first free byte    */
  811.   poolptr += _fstrlen( buff ) + 1;
  812.   wsprintf( (LPSTR) buff,"integration steps");
  813.   /* copy buff to the string pool                        */
  814.   _fstrcpy( (char __far *) poolptr,
  815.             (char __far *) buff );
  816.   /* store the pointer in outpel[i]                        */
  817.   outpel[i].title = poolptr;
  818.   /* increase i                                            */
  819.   i++;
  820.   /* increase poolptr to point to the first free byte    */
  821.   poolptr += _fstrlen( buff ) + 1;
  822.   wsprintf( (LPSTR) buff,"function evaluations");
  823.   /* copy buff to the string pool                        */
  824.   _fstrcpy( (char __far *) poolptr,
  825.             (char __far *) buff );
  826.   /* store the pointer in outpel[i]                        */
  827.   outpel[i].title = poolptr;
  828.   /* increase i                                            */
  829.   i++;
  830.   /* increase poolptr to point to the first free byte    */
  831.   poolptr += _fstrlen( buff ) + 1;
  832.   wsprintf( (LPSTR) buff,"jacobian evaluations");
  833.   /* copy buff to the string pool                        */
  834.   _fstrcpy( (char __far *) poolptr,
  835.             (char __far *) buff );
  836.   /* store the pointer in outpel[i]                        */
  837.   outpel[i].title = poolptr;
  838.   /* increase i                                            */
  839.   i++;
  840.   /* increase poolptr to point to the first free byte    */
  841.   poolptr += _fstrlen( buff ) + 1;
  842.   wsprintf( (LPSTR) buff,"last step size");
  843.   /* copy buff to the string pool                        */
  844.   _fstrcpy( (char __far *) poolptr,
  845.             (char __far *) buff );
  846.   /* store the pointer in outpel[i]                        */
  847.   outpel[i].title = poolptr;
  848.   /* increase i                                            */
  849.   i++;
  850.   /* increase poolptr to point to the first free byte    */
  851.   poolptr += _fstrlen( buff ) + 1;
  852.   wsprintf( (LPSTR) buff,"relative tolerance");
  853.   /* copy buff to the string pool                        */
  854.   _fstrcpy( (char __far *) poolptr,
  855.             (char __far *) buff );
  856.   /* store the pointer in outpel[i]                        */
  857.   outpel[i].title = spar[l].title = poolptr;
  858.   /* increase i                                            */
  859.   i++; l++;
  860.   /* increase poolptr to point to the first free byte    */
  861.   poolptr += _fstrlen( buff ) + 1;
  862.   wsprintf( (LPSTR) buff,"absolute tolerance");
  863.   /* copy buff to the string pool                        */
  864.   _fstrcpy( (char __far *) poolptr,
  865.             (char __far *) buff );
  866.   /* store the pointer in outpel[i]                        */
  867.   outpel[i].title = spar[l].title = poolptr;
  868.   /* increase i                                            */
  869.   i++; l++;
  870.   /* increase poolptr to point to the first free byte    */
  871.   poolptr += _fstrlen( buff ) + 1;
  872.   wsprintf( (LPSTR) buff,"flux resolution");
  873.   /* copy buff to the string pool                        */
  874.   _fstrcpy( (char __far *) poolptr,
  875.             (char __far *) buff );
  876.   /* store the pointer in outpel[i]                        */
  877.   outpel[i].title = spar[l].title = poolptr;
  878.  
  879.  return 0;
  880. }
  881.  
  882.  
  883. /*
  884.     make strings for reactions
  885. */
  886.  
  887. void step_string( void )
  888. {
  889.  int i, j, st, first, tempstoi[MAX_MET];
  890.  char auxstr[128];
  891.  
  892.  for( j=0; j<nsteps; j++ )
  893.  {
  894.   stepstr[j][0] = '\0';
  895.   for( i=0; i<totmet; i++ ) tempstoi[i] = 0;
  896.   for( i=0; i<MAX_MOL; i++ )
  897.    if ((*rstr)[j][i]<0) tempstoi[ -(*rstr)[j][i]-1 ]--;
  898.   for( i=0, first=1; i<totmet ; i++ )                                    /* first the substrates    */
  899.   {
  900.    st = tempstoi[i];
  901.    if( st < 0 )
  902.    {
  903.     if ( st == -1 )
  904.      wsprintf( auxstr, "%s%s", first==1 ? (LPSTR) "" : (LPSTR) " + ", &metname[i][0] );
  905.     else
  906.      wsprintf( auxstr, "%s%i*%s", first==1 ? (LPSTR) "" : (LPSTR) " + ", -st, &metname[i][0] );
  907.     _fstrcat( stepstr[j], auxstr );
  908.     first = 0;
  909.    }
  910.   }
  911.   if( revers[uc[j]] )                                            /* the connector        */
  912.    _fstrcat( stepstr[j], " = " );
  913.   else
  914.    _fstrcat( stepstr[j], " -> " );
  915.   /* setup the stoicheiometries of the products                        */
  916.   for( i=0; i<totmet; i++ ) tempstoi[i] = 0;
  917.   for( i=0; i<MAX_MOL; i++ )
  918.    if ((*rstr)[j][i]>0) tempstoi[ (*rstr)[j][i]-1 ]++;
  919.   for( i=0,  first=1; i<totmet; i++ )                        /* then the products    */
  920.   {
  921.    st = tempstoi[i];
  922.    if( st > 0 )
  923.    {
  924.     if( st == 1 )
  925.      wsprintf( auxstr, "%s%s", first==1 ? (LPSTR) "" : (LPSTR) " + ", &metname[i][0] );
  926.     else
  927.      wsprintf( auxstr, "%s%i*%s", first==1 ? (LPSTR) "" : (LPSTR) " + ", st, &metname[i][0] );
  928.     _fstrcat( stepstr[j], auxstr );
  929.     first = 0;
  930.    }
  931.   }
  932.  }
  933. }
  934.  
  935. /*
  936.   set default values when there is no .INI file
  937. */
  938.  
  939. void def_def( void )
  940. {
  941.  dft_pfo = DFT_PFO;
  942.  dft_endtime = DFT_ENDTIME;
  943.  dft_hrcz = DFT_HRCZ;
  944.  dft_debugval = DFT_DEBUGVAL;
  945.  dft_conc = DFT_CONC;
  946.  dft_const = DFT_CONST;
  947.  dft_timeu = DFT_TIMEU;
  948.  dft_concu = DFT_CONCU;
  949. }
  950.  
  951. /* sets the concentrations and kin. const. to the defaults */
  952. void conc_dft( void )
  953. {
  954.  int i, j;
  955.  
  956.  for( i=0; i<totmet; i++ ) xu[i] = dft_conc;
  957.  for( i=0; i<nsteps; i++ )
  958.   for( j=0; j<(int)ktype[kinetu[0]].nconst; j++ )
  959.    *(params[i]+j) = dft_const;
  960. }
  961.  
  962.  
  963. void numer_dft( void )
  964. {
  965.  options.reltol = DFT_RELTOL;
  966.  options.abstol = DFT_ABSTOL;
  967.  options.hrcz = dft_hrcz;
  968.  options.adams = DFT_ADAMS;
  969.  options.bdf = DFT_BDF;
  970. }
  971.  
  972. /*
  973.   set variables to default values
  974. */
  975.  
  976. void set_dfts( void )
  977. {
  978.  options.endtime = dft_endtime;
  979.  options.debug = dft_debugval;
  980.  options.dyn = DFT_DYN;
  981.  options.ss = DFT_SS;
  982.  options.txt = DFT_TXT;
  983.  options.dat = DFT_DAT;
  984.  options.pfo = dft_pfo;
  985.  strcpy( options.timeu, dft_timeu );
  986.  strcpy( options.concu, dft_concu );
  987.  options.datwidth = DFT_DATWIDTH;
  988.  options.datsep = DFT_DATSEP;
  989.  options.datmca = DFT_DATMCA;
  990.  options.datss = DFT_DATSS;
  991.  options.scan = 0;
  992.  options.scandens = (unsigned long) 1;
  993.  options.quotes = 0;
  994.  plot.x = -1;
  995.  plot.y[0] = -1;
  996.  plot.z = -1;
  997.  plot.ny = 1;
  998.  plot.type = 0;
  999.  plot.file = 0;
  1000.  plot.lines = 1;
  1001.  plot.colour = 1;
  1002.  plot.hidden = 0;
  1003.  plot.contour = 0;
  1004.  plot.logx = 0;
  1005.  plot.logy = 0;
  1006.  plot.logz = 0;
  1007.  numer_dft();
  1008. }
  1009.  
  1010.  
  1011. /*
  1012.   read default values
  1013. */
  1014.  
  1015. void get_dfts( void )
  1016. {
  1017.  def_def();
  1018.  set_dfts();
  1019. }
  1020.  
  1021.  
  1022. /*
  1023.    create a new function tree object
  1024. */
  1025.  
  1026. int new_tree( int idx )
  1027. {
  1028.  if( !eqefl )
  1029.  {
  1030.   nudf++;
  1031.   GlobalUnlock( hTree );
  1032.   hTree = GlobalReAlloc( hTree, (DWORD) nudf * sizeof( struct treet ), GMEM_ZEROINIT | GMEM_MOVEABLE );
  1033.   if( hTree == NULL )
  1034.    return IDS_ERR_NOEXEC;
  1035.   tree = ( struct treet huge * ) GlobalLock( hTree );
  1036.  }
  1037.  _fmemcpy( (void __far *) &tree[idx], (void __far *) &tr, sizeof( struct treet ) );
  1038.  return 0;
  1039. }
  1040.  
  1041. /*
  1042.   add a user-defined rate equation to the database
  1043. */
  1044.  
  1045. int new_rateq( int idx )
  1046. {
  1047.  GLOBALHANDLE hTemp;
  1048.  WORD strsize;
  1049.  int i;
  1050.  DWORD l;
  1051.  LPSTR tmpptr;
  1052.  
  1053.  /* measure the required length for the constant names                */
  1054.  for( i=0, strsize=0; i<tree[idx].nid; i++ )
  1055.   if( tree[idx].id[i][9] == (char) 0 )
  1056.    strsize += lstrlen(tree[idx].id[i]) + 1;
  1057.  sizetr += (DWORD) strsize * sizeof( char );
  1058.  l = (DWORD) (treeptr - treestr);
  1059.  /* reallocate the buffer to hold new strings                        */
  1060.  GlobalUnlock( hTreeStr );
  1061.  hTreeStr = GlobalReAlloc( hTreeStr, sizetr, GMEM_ZEROINIT | GMEM_MOVEABLE );
  1062.  if( hTreeStr == NULL ) return IDS_ERR_NOEXEC;
  1063.  treestr = GlobalLock( hTreeStr );
  1064.  treeptr = treestr + l;
  1065.  tmpptr = treeptr;
  1066.  /* copy the strings to the buffer                                    */
  1067.  for( i=0; i<tree[idx].nid; i++ )
  1068.   if( tree[idx].id[i][9] == (char) 0 )
  1069.   {
  1070.    lstrcpy( treeptr, tree[idx].id[i] );
  1071.    treeptr += lstrlen( tree[idx].id[i] ) + 1;
  1072.   }
  1073.  
  1074.  /* unlock the memory handle    */
  1075.  GlobalUnlock( hKtype );
  1076.  hTemp = GlobalReAlloc( hKtype, (DWORD) (++nrateq) * sizeof( struct kint ), GMEM_ZEROINIT | GMEM_MOVEABLE );
  1077.  if( hTemp != NULL )
  1078.  {
  1079.   hKtype = hTemp;
  1080.   ktype = ( struct kint huge * ) GlobalLock( hKtype );
  1081.   ktype[MAX_TYP+idx].nmodf = (unsigned char) tree[idx].nmodf;
  1082.   ktype[MAX_TYP+idx].nconst =(unsigned char) tree[idx].nconst;
  1083.   ktype[MAX_TYP+idx].descr = (LPSTR) tree[idx].descr;
  1084.   ktype[MAX_TYP+idx].constnam = (LPSTR) tmpptr;
  1085.   return 0;
  1086.  }
  1087.  else
  1088.  {
  1089.   ktype = ( struct kint huge * ) GlobalLock( hKtype );
  1090.   return IDS_ERR_NOEXEC;
  1091.  }
  1092. }
  1093.  
  1094.  
  1095. /*
  1096.   free global heap space allocated
  1097. */
  1098.  
  1099. void TidyGepasiVar( void )
  1100. {
  1101.  GlobalUnlock( hMetname );                            /* unlock all global handles    */
  1102.  GlobalUnlock( hStepname );
  1103.  GlobalUnlock( hStoiu );
  1104.  GlobalUnlock( hSto );
  1105.  GlobalUnlock( hLoop );
  1106.  GlobalUnlock( hParams );
  1107.  GlobalUnlock( hKtype );
  1108.  GlobalUnlock( hRstr );
  1109.  GlobalUnlock( hOutpEl );
  1110.  GlobalUnlock( hScanPar );
  1111.  GlobalUnlock( hStrPool );
  1112.  GlobalUnlock( hTreeStr );
  1113.  GlobalUnlock( hTree );
  1114.  GlobalUnlock( hTmpF );
  1115.  
  1116.  GlobalFree( hMetname );                            /* free all global mem blocks    */
  1117.  GlobalFree( hStepname );
  1118.  GlobalFree( hStoiu );
  1119.  GlobalFree( hSto );
  1120.  GlobalFree( hLoop );
  1121.  GlobalFree( hParams );
  1122.  GlobalFree( hKtype );
  1123.  GlobalFree( hRstr );
  1124.  GlobalFree( hOutpEl );
  1125.  GlobalFree( hScanPar );
  1126.  GlobalFree( hStrPool );
  1127.  GlobalFree( hTreeStr );
  1128.  GlobalFree( hTree );
  1129.  GlobalFree( hTmpF );
  1130. }
  1131.