home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / biology / gsrc208a.zip / EDNUMER.C < prev    next >
C/C++ Source or Header  |  1993-06-01  |  6KB  |  177 lines

  1. #include "copyleft.h"
  2.  
  3. /*
  4.     GEPASI - a simulator of metabolic pathways and other dynamical systems
  5.     Copyright (C) 1989, 1992  Pedro Mendes
  6. */
  7.  
  8. /*************************************/
  9. /*                                   */
  10. /*         GWSIM - Simulation        */
  11. /*        MS-WINDOWS front end       */
  12. /*                                   */
  13. /*         Numerical methods         */
  14. /*            dialog box             */
  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 <stdlib.h>
  26. #include <math.h>
  27. #include "defines.h"                    /* symbols also used in .DLG files        */
  28. #include "globals.h"                    /* gepasi's own symbols                    */
  29. #include "gwsim.h"                        /* macros, function prototypes, etc.    */
  30. #include "gep2.h"                        /* gepasi's variables                    */
  31. #include "simgvar.h"                    /* global variables                        */
  32. #include "strtbl.h"                        /* symbols for the string table            */
  33.  
  34. #pragma alloc_text( CODE10, EdNumer )
  35.  
  36. BOOL FAR PASCAL EdNumer(HWND hDlg, WORD message, WORD wParam, LONG lParam)
  37. {
  38.  static    HWND    hRtol, hAtol, hAdams, hBdf, hFres;
  39.  char buff[128];
  40.  int len;
  41.  double daux;
  42.  
  43.  switch( message )
  44.  {
  45.   case WM_INITDIALOG:
  46.    /* get handles to controls                                        */
  47.    hRtol  = GetDlgItem( hDlg, IDE_M0 );
  48.    hAtol  = GetDlgItem( hDlg, IDE_M1 );
  49.    hAdams = GetDlgItem( hDlg, IDE_M2 );
  50.    hBdf   = GetDlgItem( hDlg, IDE_M3 );
  51.    hFres  = GetDlgItem( hDlg, IDE_M4 );
  52.  
  53.    /* fill in the current set of options                            */
  54.    gcvt( options.reltol, 16, buff );
  55.    SendMessage( hRtol, WM_SETTEXT, 0, (DWORD)(LPSTR) buff );
  56.    gcvt( options.abstol, 16, buff );
  57.    SendMessage( hAtol, WM_SETTEXT, 0, (DWORD)(LPSTR) buff );
  58.    wsprintf( (LPSTR) buff, "%d", options.adams );
  59.    SendMessage( hAdams, WM_SETTEXT, 0, (DWORD)(LPSTR) buff );
  60.    wsprintf( (LPSTR) buff, "%d", options.bdf );
  61.    SendMessage( hBdf, WM_SETTEXT, 0, (DWORD)(LPSTR) buff );
  62.    gcvt( options.hrcz, 16, buff );
  63.    SendMessage( hFres, WM_SETTEXT, 0, (DWORD)(LPSTR) buff );
  64.    return TRUE;
  65.  
  66.   case WM_COMMAND:
  67.    switch( wParam )
  68.    {
  69.     case IDC_DEFAULTS:
  70.      numer_dft();
  71.      SendMessage( hDlg, WM_INITDIALOG, 0, 0 );
  72.      return TRUE;
  73.  
  74.     case IDC_HELP:            /* Help on this Dialog Box                */
  75.         WinHelp( hDlg, (LPSTR) szHelpFile, HELP_KEY, (DWORD) (LPSTR) "Numerical parameters" );
  76.         return TRUE;
  77.  
  78.     case IDOK:
  79.      /* read all variables from the controls        */
  80.      len = (int) SendMessage( hRtol, WM_GETTEXT, (WORD) sizeof( buff ), (DWORD)(LPSTR) buff );
  81.      if( len>0 ) daux = strtod( buff, NULL );
  82.      else daux = options.reltol;
  83.      if( (daux==HUGE_VAL) || (daux==-HUGE_VAL) )
  84.      {
  85.       LoadString(hInst, IDS_ERR_OVERFLOW, szString, sizeof(szString));
  86.       MessageBox(hDlg, szString, NULL, MB_ICONEXCLAMATION);
  87.       SetFocus( hRtol );
  88.       return TRUE;
  89.      }
  90.      if( (daux<=0) )
  91.      {
  92.       LoadString(hInst, IDS_ERR_ZEROBAD, szString, sizeof(szString));
  93.       MessageBox(hDlg, szString, NULL, MB_ICONEXCLAMATION);
  94.       SetFocus( hRtol );
  95.       return TRUE;
  96.      }
  97.      options.reltol = daux;
  98.  
  99.      len = (int) SendMessage( hAtol, WM_GETTEXT, (WORD) sizeof( buff ), (DWORD)(LPSTR) buff );
  100.      if( len>0 ) daux = strtod( buff, NULL );
  101.      else daux = options.abstol;
  102.      if( (daux==HUGE_VAL) || (daux==-HUGE_VAL) )
  103.      {
  104.       LoadString(hInst, IDS_ERR_OVERFLOW, szString, sizeof(szString));
  105.       MessageBox(hDlg, szString, NULL, MB_ICONEXCLAMATION);
  106.       SetFocus( hAtol );
  107.       return TRUE;
  108.      }
  109.      if( (daux<=0) )
  110.      {
  111.       LoadString(hInst, IDS_ERR_ZEROBAD, szString, sizeof(szString));
  112.       MessageBox(hDlg, szString, NULL, MB_ICONEXCLAMATION);
  113.       SetFocus( hAtol );
  114.       return TRUE;
  115.      }
  116.      options.abstol = daux;
  117.  
  118.      len = (int) SendMessage( hAdams, WM_GETTEXT, (WORD) sizeof( buff ), (DWORD)(LPSTR) buff );
  119.      if( len>0 ) len = atoi( buff );
  120.      else len = options.adams;
  121.      if( (len<=0) )
  122.      {
  123.       LoadString(hInst, IDS_ERR_ZEROBAD, szString, sizeof(szString));
  124.       MessageBox(hDlg, szString, NULL, MB_ICONEXCLAMATION);
  125.       SetFocus( hAdams );
  126.       return TRUE;
  127.      }
  128.      options.adams = len;
  129.  
  130.      len = (int) SendMessage( hBdf, WM_GETTEXT, (WORD) sizeof( buff ), (DWORD)(LPSTR) buff );
  131.      if( len>0 ) len = atoi( buff );
  132.      else len = options.bdf;
  133.      if( (len<=0) )
  134.      {
  135.       LoadString(hInst, IDS_ERR_ZEROBAD, szString, sizeof(szString));
  136.       MessageBox(hDlg, szString, NULL, MB_ICONEXCLAMATION);
  137.       SetFocus( hBdf );
  138.       return TRUE;
  139.      }
  140.      options.bdf = len;
  141.  
  142.      len = (int) SendMessage( hFres, WM_GETTEXT, (WORD) sizeof( buff ), (DWORD)(LPSTR) buff );
  143.      if( len>0 ) daux = strtod( buff, NULL );
  144.      else daux = options.hrcz;
  145.      if( (daux==HUGE_VAL) || (daux==-HUGE_VAL) )
  146.      {
  147.       LoadString(hInst, IDS_ERR_OVERFLOW, szString, sizeof(szString));
  148.       MessageBox(hDlg, szString, NULL, MB_ICONEXCLAMATION);
  149.       SetFocus( hFres );
  150.       return TRUE;
  151.      }
  152.      if( (daux<=0) )
  153.      {
  154.       LoadString(hInst, IDS_ERR_ZEROBAD, szString, sizeof(szString));
  155.       MessageBox(hDlg, szString, NULL, MB_ICONEXCLAMATION);
  156.       SetFocus( hFres );
  157.       return TRUE;
  158.      }
  159.      options.hrcz = daux;
  160.  
  161.  
  162.      /* signal that changes were made                */
  163.      notsaved = 1;
  164.  
  165.      /* close the dialog box and return                */
  166.      EndDialog( hDlg, IDOK );
  167.      return TRUE;
  168.  
  169.     case IDCANCEL:
  170.      /* close the dialog box and return            */
  171.      EndDialog( hDlg, IDCANCEL );
  172.      return TRUE;
  173.    }
  174.  
  175.   default: return FALSE;
  176.  }
  177. }