SG_VALU Data Structure


The SG_VALU data structure is designed to accommodate data values of an attribute after SansGUI Data Type Funneling, explained in the previous chapter.

SG_VALU Structure Elements

The SG_VALU data structure contains the following elements:

SG_VALU Structure in C

The implementation of SG_VALU structure in the C programming language (found in SGdll.h in subdirectory inc under the installation directory) is listed as following:

typedef struct SG_VALU_tag

{

    SG_CONST UINT nType;

    SG_CONST INT iSize;

    SG_CONST INT iCols;

    INT iRows;

    union

    {

        void *SG_CONST vData;

        INT *SG_CONST iData;

        FLOAT *SG_CONST fData;

        DOUBLE *SG_CONST dData;

        TCHAR *SG_CONST cData;

        TCHAR *SG_CONST *SG_CONST sData;

    };

} SG_VALU;

SansGUI has been built with 8 byte packing (default in MSVC and CVF) for member alignment in all data structures. However, because the members are either integer quantities or pointers, they are all 4 bytes implemented in 32-bit systems. SG_CONST is a macro that should be treated as const. The INT, UINT, FLOAT, DOUBLE and TCHAR are macros defined as int, unsigned int, float, double and char, respectively. They may be defined with system dependencies in the header file SGtypes.h in directory inc under the installation directory. The usages of the elements are explained in the following sections:

nType

This structure member contains the type information regarding the data array. In addition to the types defined in the Object Data Representation section in Chapter 1, nType is also used for the scope of the attribute/variable and the status of the value:

The types defined in the Object Data Representation section can be obtained by performing a bitwise-AND operation of nType and SG_TYPE_MASK:

nType & SG_TYPE_MASK

Alternatively, you can use the modulo operation of nType and SG_TYPE_MASK to obtain the actual type:

nType % SG_TYPE_MASK

The scope and status are fetched by the certain bit as stated above. There are predicate macros, started with SG_IsNull, defined in SGdll.h header file for your convenience.

iSize, iCols, and iRows

These three integer values specify the dimension of the data array. In general, iSize indicates the total size of the data array, iCols indicates the number of columns, and iRows indicates the number of rows in the multi-dimensional array. When the data array is 3-dimensional, the third dimension is represented by the number of sheets, which can be calculated by:

Number of sheets = iSize / iCols / iRows

There are, however, some issues in specific types of data arrays:

Union of Data Arrays

The data array stores the values of an attribute/variable. From the data structure, it is a union of different typed pointers pointing to the beginning of the data array.

To access the third integer from the data array (0-based), for example, use

SG_VALU* pValue;

/* initialize pValue to point to

 * a proper value structure

 */

INT iThird = pValue->iData[2];

SG_VALU Structure in Fortran

The data structure and the memory allocation module in SansGUI have been implemented in the C programming language. An include file named SGdllf.h is provided for users who program in Fortran. The data structure TYPE in Fortran 90 and the POINTER feature in Compaq Visual Fortran (CVF) are used to access the structure members. For details on these structure members, please consult the SG_VALU Structure in C section above.

      type SG_VALU

          sequence

          integer :: nType

          integer :: iSize

          integer :: iCols

          integer :: iRows

          integer(4) :: vData

      end type SG_VALU

and there are access pointers defined in the header file for convenience.

      integer, dimension(*) :: iData

      POINTER(PTR_iData, iData)

      real*4 dimension(*) :: fData

      POINTER(PTR_fData, fData)

      real*8 dimension(*) :: dData

      POINTER(PTR_dData, dData)

      character, dimension(*) :: cData

      POINTER(PTR_cData, cData)

We explicitly declare integer(4) for all pointers in the data structure. Being different from the C implementation, the variant types of data array can be referred to via the vData pointer. Suppose zValues is an element of SG_VALU type, we can access the third integer from it (1-based) as:

integer :: iThird

PTR_iData = zValues%vData

iThird = iData(3)

More elaborated examples can be found in the next section SG_OBJ Data Structure and the DLL Function Prototype section in Chapter 3.

 



C:\FH_Suite\htmlgifs\home.gif SansGUI Data Object Format SG_OBJ Data Structure

SansGUI Modeling and Simulation Environment Version 1.2

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

http://protodesign-inc.com