Source Code for Project MatPlot


The following source file, led by a gray banner, contains all the class functions needed for Project MatPlot.  The sections highlighted by a yellow background Color are manually entered.  Code sections with white background color are generated by the SansGUI Source Code Framework.  The source file is compiled into a dynamic linked library to be invoked by SansGUI during simulation runs.

For more details about this example, please read A Tour of SansGUI Examples in the SansGUI Getting Started Guide.

Implementation in C/C++ (MSVC)

Functions in Class Matrix.MyMatrix    [Go To Top]

/* Matrix_MyMatrix.c
 * - DLL routines for class <Reference>Matrix.MyMatrix
 * DATE: Thursday, December 07, 2000 TIME: 03:27:25 PM
 * The skeleton of this file is generated by SansGUI(tm)
 */

#include <stdio.h>

#include <string.h>
#include <math.h>

#include "SGdll.h"

#ifdef __cplusplus
extern "C"
{
#endif

SG_EXPORT SG_SIM_FUNC SG_xEndEdit_Matrix_MyMatrix;
SG_EXPORT SG_SIM_FUNC SG_xLoadSize_Matrix_MyMatrix;
SG_EXPORT SG_SIM_FUNC SG_xLoad_Matrix_MyMatrix;
SG_EXPORT SG_SIM_FUNC SG_xEval_Matrix_MyMatrix;

#ifdef __cplusplus
}
#endif

/* Macros for attribute indices in class version [1.0.alpha.3] */
#define SG_NDX_ICOLS 0 /* iCols - Number of Columns */
#define SG_NDX_IROWS 1 /* iRows - Number of Rows */
#define SG_NDX_ISHEETS 2 /* iSheets - Number of Sheets */
#define SG_NDX_FMATDATA 3 /* fMatData - Matrix Data */

#define SG_NDX_NCYCLE 3 /* from SimCtrl.Cycle.MatPlot class */
#define SG_NDX_FDATA1 9
#define SG_NDX_FDATA2 10
#define SG_NDX_FSUM 11

/* ============================================================
 * SG_xLoadSize - Resize for Load
 * ------------------------------------------------------------
 */
SG_RET_CODE SG_xLoadSize_Matrix_MyMatrix(SG_OBJ *const self,
          SG_OBJ *const simCtrl, SG_OBJ *const chgChild,
          SG_OBJ *const refObjs[], const INT *const piRefObjs,
          SG_OBJ *const adjObjs[], const INT *const piAdjObjs,
          SG_OBJ *const lnkObjs[], const INT *const piLnkObjs,
          TCHAR *const cMessage, const INT iMsgLen,
          TCHAR *const cCommand, const INT iCmdLen,
          SG_FILE *const pOutFile )
{
    /* TODO: declare your local variables here */

    if (!SG_IsSchemaOK(self->nSGobjSchema))
        return SG_R_SCHM;

    /* TODO: put your simulator code here */

    self->zValues[SG_NDX_ICOLS].iData[0] = 2;
    self->zValues[SG_NDX_IROWS].iData[0] = 360;

    return SG_R_OK;
}

/* ============================================================
 * SG_xLoad - Load Data
 * ------------------------------------------------------------
 */
SG_RET_CODE SG_xLoad_Matrix_MyMatrix(SG_OBJ *const self,
          SG_OBJ *const simCtrl, SG_OBJ *const chgChild,
          SG_OBJ *const refObjs[], const INT *const piRefObjs,
          SG_OBJ *const adjObjs[], const INT *const piAdjObjs,
          SG_OBJ *const lnkObjs[], const INT *const piLnkObjs,
          TCHAR *const cMessage, const INT iMsgLen,
          TCHAR *const cCommand, const INT iCmdLen,
          SG_FILE *const pOutFile )
{
    /* TODO: declare your local variables here */

    FLOAT fRadians;
    const INT iCols = self->zValues[SG_NDX_ICOLS].iData[0];
    const INT iRows = self->zValues[SG_NDX_IROWS].iData[0];
    int i;

    if (!SG_IsSchemaOK(self->nSGobjSchema))
    return SG_R_SCHM;

    /* TODO: put your simulator code here */

    if (iCols < 2)
    {
        strcpy(cMessage, "Error: need to have at least 2 columns.");
        return SG_R_STOP;
    }

    for (i = 0; i < iRows; i++)
    {
        fRadians = 3.14159f / 180.f * (float)i;
        self->zValues[SG_NDX_FMATDATA].fData[i] = (float)sin(fRadians);
        self->zValues[SG_NDX_FMATDATA].fData[iRows + i] = (float)cos(fRadians);
    }

    return SG_R_OK;
}

/* ============================================================
 * SG_xEval - Evaluation
 * ------------------------------------------------------------
 */
SG_RET_CODE SG_xEval_Matrix_MyMatrix(SG_OBJ *const self,
          SG_OBJ *const simCtrl, SG_OBJ *const chgChild,
          SG_OBJ *const refObjs[], const INT *const piRefObjs,
          SG_OBJ *const adjObjs[], const INT *const piAdjObjs,
          SG_OBJ *const lnkObjs[], const INT *const piLnkObjs,
          TCHAR *const cMessage, const INT iMsgLen,
          TCHAR *const cCommand, const INT iCmdLen,
          SG_FILE *const pOutFile )
{
    /* TODO: declare your local variables here */

    const INT nCycle = simCtrl->zValues[SG_NDX_NCYCLE].iData[0];
    const INT iCols = self->zValues[SG_NDX_ICOLS].iData[0];
    const INT iRows = self->zValues[SG_NDX_IROWS].iData[0];
    const INT iNdx = nCycle % iRows;
    FLOAT *pfData1 = &simCtrl->zValues[SG_NDX_FDATA1].fData[0];
    FLOAT *pfData2 = &simCtrl->zValues[SG_NDX_FDATA2].fData[0];

    if (!SG_IsSchemaOK(self->nSGobjSchema))
        return SG_R_SCHM;

    /* TODO: put your simulator code here */

    if (iCols < 2)
    {
        strcpy(cMessage, "Error: at least 2 columns in the matrix.");
        return SG_R_STOP;
    }

    if (iRows < 1)
    {
        strcpy(cMessage, "Error: at least 1 row in the matrix.");
        return SG_R_STOP;
    }

    /* look up value from matrix */
    *pfData1 = self->zValues[SG_NDX_FMATDATA].fData[iNdx];
    *pfData2 = self->zValues[SG_NDX_FMATDATA].fData[iRows + iNdx];

    /* calculate sum of data */
    simCtrl->zValues[SG_NDX_FSUM].fData[0] = *pfData1 + *pfData2;

    return SG_R_OK;
}

 


SansGUI Modeling and Simulation Environment version 1.2

Copyright © 2000-2003 ProtoDesign, Inc. All rights reserved.

http://protodesign-inc.com