GAUSS Engine

Q. My Constrained Optimization, Constrained Maximum Likelihood, CurveFit, FANPAC, FANPACMT and Maximum Likelihood problems that require keyboard input run fine under GAUSS but hang when run using the GAUSS Engine? Why?

A. The problem is that the GAUSS Engine does not automatically hook keyboard input to the calling program for the GAUSS function KEY. You need to provide a callback using GAUSS_HookProgramInputChar() or you can turn off the requests for keyboard input in your GAUSS program.

To provide a callback, see the documentation for GAUSS_HookProgramInputChar() in the GAUSS Engine manual. You need to provide a callback function that always returns a zero.

Turn off the requests for keyboard input by setting the global variables _co_Key to zero for Constrained Optimization, _cml_Key to zero for Constrained Maximum Likelihood, _cv_Key to zero for CurveFit, _ml_Key to zero for Maximum Likelihood.

Keyboard input for sqpSolvemt in the Run-Time Library is disabled by setting c.disableKey to a nonzero value where "c" is an instance of an sqpSolvemt control structure.  For example,

      struct sqpSolvemtControl c;
      c = sqpSolvemtControlCreate;
      c.disableKey = 1;

The FANPAC applications module comes with NLP, an optimization program that uses keyboard input. This can be disabled by setting _nlp_key to zero in the nlp.dec file. From a FANPAC program it can be disabled by writing a proc with no input or output arguments that sets _nlp_key to zero, and then assigning the pointer to that proc to _fan_nlpGlobals. For example,

      proc(0)= globs;
      _nlp_key = 0;
      endp;
      _fan_nlpGlobals = &globs;

FANPAC MT uses the optimizer sqpSolvemt in the Run-Time Library. To disable keyboard input from a FANPAC MT program, write a procedure that takes an sqpSolvemtControl instance as an input and output argument,and assign a pointer to that procedure to the sqpSolvemtControlProc member of an instance of a fanControl structure. In that procedure set c.disableKey to a nonzero value where "c" is an instance of the sqpSolvemtControl structure. For example,

      proc sqp(struct sqpSolvemtControl c);
        c.disableKey = 1;
        retp(c);
     endp;

    struct fanControl f;
    f = fanControlCreate;
    f.sqpSolvemtControlProc = &sqp;

[Back]

Q. How do I call the GAUSS Engine from VB?

A. You need to write a wrapper (in C) linked to MTENG. You design the calls in the wrapper so that they can be called from VB. And then you declare these calls in VB.

  1. Create a wrapper - this is a win32 dynamic link library (dll), created using VC, or equivalent. This dll will link to MTENG.DLL, so you need to include mteng.h and mteng.lib in the project. Since this wrapper will need to talk to mteng.dll, you will need mteng.dll on the application folder (in your C project's Debug or Release folder). Call this wrapper vbeng.dll.

  2. For each GAUSS Engine command, you will need an entry in the wrapper. Arguments types that cannot be passed to VB are declared in the wrapper as a global. VB requires that the C functions be compiled with the __stdcall calling convention.

        // Globals
        WorkspaceHandle_t* wh;

        int __stdcall ge_Initialize()
        {
           int ret;
           char buf[256];
           if( (ret = GAUSS_Initialize()) != 0)
           {sprintf(buf,"Error: GAUSS_Initialize return code = %u",ret);
           MessageBox(0,buf,"MTENG",0);
           return 1;
           }
           return 0;
        }

        int __stdcall ge_CreateWorkspace(char *wsName )
        {
           if ( (wh = GAUSS_CreateWorkspace(wsName)) == NULL)
                { MessageBox(0,"CreateWorkspace Failed","MTENG",0);
                return 1;
                }

           return 0;
        }

  3. Ensure that name decoration does not occur when the file is compiled by adding a \.def file to the project, i.e.

        LIBRARY mylib.dll
        EXPORTS
           ge_Initialize
           ge_CreateWorkspace

  4. For each GAUSS Engine command defined in vbeng.dll, one needs a corresponding VB definition. Input arguments must be passed by value.

        Private Declare Function ge_CreateWorkspace Lib "vbeng.dll"
           (ByVal wsname _As String) As Long
        Private Declare Function ge_Initialize Lib "vbeng.dll" () As Long

  5. VB calls the vbeng.dll in the standard manner:

    Public Function GaussInitialize()

    ' Initializes GAUSS

           On Error GoTo errGaussInitialize
           ge_Initialize
           Exit Function

           errGaussInitialize:
              ShowError "GaussInitialize", Err.Number, Err.Description
              End Function

              Public Function WorkspaceCreate(ByVal wsname as String)

                  ' Creates workspace

                       On Error GoTo errGeWorkspaceCreate
                            WorkspaceCreate = ge_CreateWorkspace(wsname)
                                Exit Function

                                     errGeWorkspaceCreate:
                                         ShowError "WorkspaceCreate", Err.Number,
                                         Err.Description
                                              End Function

  6. Similar techniques can be used for all types that cannot be passed from VB.

  7. As an alternative, there is a 3rd party application called Mercury_GE, produced by Econotron Software, which does the entire job, so that the Engine can be called from VB or Excel, with a minimum of coding. A full description is posted at www.econotron.com. This product is available from Aptech Systems.
[Back]


© Copyright 2004-2008.   Aptech Systems, Inc.
Black Diamond, WA.  All Rights Reserved Worldwide.