Spark! Fuzzy Logic Editor Help


Variables | Sets | Rules | API | Integration | Tutorial


load()

Loads a Spark! model for use in your application.

int load(const char* file_name, bool debug = false)

Parameters

file_name - Path and filename of the Spark! model to load 
debug - Optional parameter.  If true, Spark! is allowed to open the model while the model is used in your application.  If false you have exclusive access to the file. (see Notes below)  

Return Value

0 - Success
 
-100 - Error loading the SparkModel.dll file (SparkModelWrapper only).  Call GetLastError() to get the error. (see Notes below)  
 
-200 - Error getting a function pointer (SparkModelWrapper only).  Call GetLastError() to get the error. (see Notes below)  
 
Anything else - Error loading the file.  Call get_msg_textA() to get the error text.

Remarks

load() is called after an object is created to load a Spark! model.

Example


#include <iostream.h>
#include "SparkModel.h"

int main(int argc, char* argv[])
{
    int            return_val;   // return value from funcs
    SparkModel     model;         // model to load

    // load the SparkDemo model in debug mode
    return_val = model.load("../SparkDemo1.spk", true); 

    if (return_val)
        {
        // there was an error loading the model...
        // if the error is -100 or -200 we had an error in a system call,
        // otherwize we can get the error text
        if (return_val == -100 || return_val == -200)
            {
            DWORD err = GetLastError();
            cout << "Error calling Load(). GetLastError() returned: " << err << endl;
            }
    else
            {
            const char* err = model.get_msg_textA();
            cout << "Error calling Load(): " << err << endl;
            }
    } // end if return_val

} // end main()

 

Notes

File locking of the Spark! model is performed via mutexes.  At the most only two applications (Spark! and your application) can have the Spark! model open on one machine.  There is nothing stopping someone on another computer from opening the model if it is available over a network.

The following table shows the allowable scenarios in which two applications can have the same model loaded.  Spark! always loads the model in "debug" mode, you application ("custom" below) can open a  model for "exclusive" access or in "debug" mode.

  Spark! Custom Debug Custom Exclusive
Spark! Error OK Error
Custom Debug OK Error Error
Custom Exclusive Error Error Error

Return Values

If you get a return value of -100 or -200, there was a problem loading the DLL or a function inside the DLL.  This is why we don't use the standard SparkModel error reporting to find out what the error was.  In most cases the error reporting objects were not created.