Using Table Objects


A Table unit conversion object enables you to convert an linear array (vector) of values from one measuring unit to five different units. The first invocation of a new Table object leads you to the first tab, the Specification tab, in the Object Properties dialog. You can enter the number of data values you want to convert to the Table Size field. The default Table Size is set to 1, meaning that you can use it to convert a single value to five different units here; rather than using the corresponding Collection object to convert the value from one unit to another.

The procedures of using the Table object is summarized as following:

 

Generate/Title.jpg

 

Check Data Button

The Check Data button is connected to the only routine implemented in the Unit Conversion program. The behavior is to copy all the data values from the first column to the other five columns. You can override this default behavior as needed. However, the internal data for all the columns are stored and manipulated in their base unit only. Values of different units are shown in the presentation layer (user interface), not the data manipulation layer (program access). Also, the table data are stored in row-major order. That is, in each data column, all the data in Data-1 sheet are stored in a linear order followed by data in Data-2 sheet, and so on.

Load Data Button

The Load Data buttons does not perform any operation by default. When clicked, two user overriding functions will be called:

You are encouraged to read Chapter 6 Overriding Simulator Routines of the SansGUI User's Guide to find out all the details. Here we include two overriding routines implemented in either MSVC++ or CVF as an example. When you have the user overriding DLL built, you need to enter the DLL paths in the DLL Override tab so that the functions can be called when you click on the Load Data button. If you do not know how to enter the DLL paths into the Dynamic-Linked Library fields, please check the Specifying File Paths section.

MSVC++ Example

The example routines simply specify 100 rows in the data table and populate each data cell with its index value. The highlighted code sections (in red) are manually entered; others are from the skeleton code for user overriding functions in the SansGUI environment.

/* Table.cpp - sample user DLL override framework for C/C++

 * Copyright (C) 2000-2001 ProtoDesign, Inc.

 * SansGUI(tm) licensee has the permission to copy and modify the codes in this file

 * under the terms in the license agreement.

 */

 

#include <stdio.h>

#include <string.h>

 

#define SG_OVERRIDE_FUNC /* to use the function declarations in SGdll.h */

#include "SGdll.h"

#undef SG_OVERRIDE_FUNC /* just release the special definition */

 

#define SG_NDX_ISIZE 0

#define SG_NDX_ISHEETS 1

#define SG_NDX_FUSER 2

#define TABLE_SIZE 100

 

/* ===========================================================================

 * SG_xLoadSize - called before SG_xLoad is called for resizing array

 * ---------------------------------------------------------------------------

 */

SG_RET_CODE SG_xLoadSize(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 )

{

    if (!SG_IsSchemaOK(self->nSGobjSchema))

        return SG_R_SCHM; /* always check the object's schema version */

 

    /* TODO: put your simulator code here */

    /* Specify the size of the table for SansGUI to allocate */

    self->zValues[SG_NDX_ISIZE].iData[0] = TABLE_SIZE;

 

    return SG_R_OK;

}

/* ===========================================================================

 * SG_xLoad - called when the user clicks on the Load Data button in editor

 * ---------------------------------------------------------------------------

 */

SG_RET_CODE SG_xLoad(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 )

{

    INT i;

 

    if (!SG_IsSchemaOK(self->nSGobjSchema))

        return SG_R_SCHM; /* always check the object's schema version */

 

    /* TODO: put your simulator code here */

    /* Populate the table with the sequence numbers as its values */

    for (i = 0; i < TABLE_SIZE; i++)

        self->zValues[SG_NDX_FUSER].fData[i] = (FLOAT)i + 1.0f;

 

    return SG_R_OK;

}

/* ===========================================================================

 */

CVF Example

The example routines simply specify 100 rows in the data table and populate each data cell with its index value. The highlighted code sections (in red) are manually entered; others are from the skeleton code for user overriding functions in the SansGUI environment.

! Table.f - sample user DLL override framework for Fortran

! Copyright (C) 2000-2001 ProtoDesign, Inc.

! SansGUI(tm) licensee has the permission to copy and modify the codes in this file

! under the terms in the license agreement.

 

! ======================================================================

! SG_xLoadSize - called before SG_xLoad is called for resizing array

! ----------------------------------------------------------------------

      integer function SG_xLoadSize(self, &

     & simCtrl, chgChild, &

     & pRefObjs, iRefObjs, &

     & pAdjObjs, iAdjObjs, &

     & pLnkObjs, iLnkObjs, &

     & cMessage, cCommand, pOutFile )

!DEC$ IF DEFINED (_DLL)

!DEC$ ATTRIBUTES DLLEXPORT :: SG_xLoadSize

!DEC$ END IF

      include "SGdllf.h"

 

      ! TODO: declare your local variables here

      integer, dimension(*) :: iSize

      POINTER(PTR_iSize, iSize)

      integer, parameter :: SG_NDX_ISIZE = 1

      integer, parameter :: TABLE_SIZE = 100

 

      if (self%nSGobjSchema .ne. SG_OBJ_SCHEMA) then

          SG_xLoadSize = SG_R_SCHM

          return

      end if

 

      ! TODO: put your simulator code here

      ! Specify the size of the table for SansGUI to allocate

      PTR_zValues = self%pzValues

      PTR_iSize = zValues(SG_NDX_ISIZE)%vData

      iSize(1) = TABLE_SIZE

 

      SG_xLoadSize = SG_R_OK

      return

      end

 

! ======================================================================

! SG_xLoad - called when the user clicks on the Load Data button in editor

! ----------------------------------------------------------------------

      integer function SG_xLoad(self, &

     & simCtrl, chgChild, &

     & pRefObjs, iRefObjs, &

     & pAdjObjs, iAdjObjs, &

     & pLnkObjs, iLnkObjs, &

     & cMessage, cCommand, pOutFile )

!DEC$ IF DEFINED (_DLL)

!DEC$ ATTRIBUTES DLLEXPORT :: SG_xLoad

!DEC$ END IF

      include "SGdllf.h"

 

      ! TODO: declare your local variables here

      integer, dimension(*) :: iSize

      real*4, dimension(*) :: fUser

      integer :: i

      POINTER(PTR_iSize, iSize)

      POINTER(PTR_fUser, fUser)

      integer, parameter :: SG_NDX_ISIZE = 1

      integer, parameter :: SG_NDX_FUSER = 3

 

      if (self%nSGobjSchema .ne. SG_OBJ_SCHEMA) then

          SG_xLoad = SG_R_SCHM

          return

      end if

 

      ! TODO: put your simulator code here

      ! Populate the table with the sequence numbers as its values

      PTR_zValues = self%pzValues

      PTR_iSize = zValues(SG_NDX_ISIZE)%vData

      PTR_fUser = zValues(SG_NDX_FUSER)%vData

 

      do i = 1, iSize(1)

          fUser(i) = i

      end do

 

      SG_xLoad = SG_R_OK

      return

      end

! ======================================================================

 



Welcome to Unit Conversion for SansGUI Using Collection Objects Using Matrix Objects

Unit Conversion for SansGUI Version 1.1

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

http://protodesign-inc.com