/* ** Title: Matrix ** SCCSid: %W% %E% %U% ** CCid: %W% %E% %U% ** Author: Informix Software, Inc. ** Created: 06/11/1998 14:53 ** Description: This is the generated 'C' file for the Matrix DataBlade. ** Comments: Generated for project Matrix.3.6 */ /* ** The following is placed here to insure ** that name "mangling" does not occur. */ #ifdef __cplusplus extern "C" { #endif /* Standard library includes. */ #include #include #include #include /* Used by Informix GLS routines. */ #include /* Include when accessing the Informix API. */ #include /* This is the project include file. */ #include "Matrix.h" /* Local defines */ #define MATRIX_MAX_NUM_SIZE 24 /**************************************************************** ** Function name: ** ** dbException -- Print an error message. ** ** Description: ** ** This routine really should use the system 'errors' table and ** a printf-style varargs list to display error messages. The ** example code has hard-coded error messages; this makes ** localization and other changes to the error messages harder, ** since it requires recompiling the code. ** ** For simplicity of this example, however, we hard-code error ** message strings in this file. Other examples correctly use ** error codes and the LIBMI mi_db_error_raise() routine. ** ***************************************************************** */ void dbException( char *msg ) { mi_db_error_raise((MI_CONNECTION *)NULL, MI_EXCEPTION, msg); /* not reached */ } /**************************************************************** ** Function name: ** ** matrix_sscanf -- Returns ptr to the new position ** after sscanf ** ** Description: ** ** This is a support routine used by the matrix input code to ** parse the user-supplied matrix string. ** ***************************************************************** */ static char * matrix_sscanf( char *ps, char format[], double *pb ) { mi_integer nbytes; char msg[64]; if( 1 != sscanf( ps, format, pb, &nbytes ) ) dbException( "Input data format error" ); if (nbytes > MATRIX_MAX_NUM_SIZE) { sprintf(msg, "Maximum size of a number cannot exceed %d characters", MATRIX_MAX_NUM_SIZE); dbException( msg ); } ps += nbytes; return ps; } /**************************************************************** ** Function name: ** ** _noOfRowsAndCols -- Compute the number of rows and ** columns in an input matrix. ** ** Description: ** ** Parses the textual representation of the matrix and counts ** the number of rows and columns. This is a support routine for ** the matrix input code. On error, it raises an exception and ** aborts the command. ** ***************************************************************** */ static void _noOfRowsAndCols( char *ps, mi_integer *pNoOfRows, mi_integer *pNoOfCols ) { mi_integer nRows, nCols, nCurrCols; enum { START, BEGINMATRIX, BEGINCOL, ENDROW, NUMBER, DECIMAL, ENDNUMBER, ENDMATRIX } state; nRows = 0; nCols = 0; nCurrCols = 0; state = START; do { switch( state ) { case START: if( isspace( *ps ) ) state = START; else if ('(' == (*ps)) state = BEGINMATRIX; else dbException("Invalid character"); break; case BEGINMATRIX: if( isspace( *ps ) ) state = BEGINMATRIX; else if ('(' == (*ps)) state = BEGINCOL; else dbException("Invalid character"); break; case BEGINCOL: if( isspace( *ps ) ) state = BEGINCOL; else if (isdigit(*ps) || '+' == (*ps) || '-' == (*ps) ) state = NUMBER; else if ('.' == (*ps)) state = DECIMAL; else dbException("Invalid character"); break; case NUMBER: if (isdigit(*ps) || '+' == (*ps) || '-' == (*ps) || 'E' == (*ps)) state = NUMBER; else if ('.' == (*ps)) state = DECIMAL; else if( ')' == (*ps) ) { nCurrCols++; if ((nCols) && (nCurrCols != nCols)) dbException("Incorrect number of columns"); else { nCols = nCurrCols; nCurrCols = 0; nRows++; } state = ENDROW; } else if( isspace( *ps ) ) state = ENDNUMBER; else if (',' == (*ps)) {nCurrCols++; state = BEGINCOL;} else dbException("Invalid character"); break; case DECIMAL: if (isdigit(*ps) || '+' == (*ps) || '-' == (*ps) || 'E' == (*ps)) state = DECIMAL; else if( ')' == (*ps) ) { nCurrCols++; if ((nCols) && (nCurrCols != nCols)) dbException("Incorrect number of columns"); else { nCols = nCurrCols; nCurrCols = 0; nRows++; } state = ENDROW; } else if( isspace( *ps ) ) state = ENDNUMBER; else if (',' == (*ps)) {nCurrCols++; state = BEGINCOL;} else dbException("Invalid character"); break; case ENDNUMBER: if( ')' == (*ps) ) { nCurrCols++; if ((nCols) && (nCurrCols != nCols)) dbException("Incorrect number of columns"); else { nCols = nCurrCols; nCurrCols = 0; nRows++; } state = ENDROW; } else if( isspace( *ps ) ) state = ENDNUMBER; else if (',' == (*ps)) {nCurrCols++; state = BEGINCOL;} else dbException("Invalid character"); break; case ENDROW: if( ')' == (*ps) ) state = ENDMATRIX; else if( isspace( *ps ) || (',' == (*ps)) ) state = ENDROW; else if ('(' == (*ps)) state = BEGINCOL; else dbException("Invalid character"); break; case ENDMATRIX: if( (isspace( *ps )) || !(*ps) ) state = ENDMATRIX; else dbException("Invalid character"); break; } } while (*ps++); *pNoOfRows = nRows; *pNoOfCols = nCols; } /* {{FUNCTION(851d2d80-5f56-11d0-93a5-00a0c9202325) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** Matrix2dSend ** ** Description: ** ** The binary send function is used to convert an instance of a ** data type between its internal representation on the server and ** on the client. ** ** Special Comments: ** ** Support routine for opaque type Matrix2d returns mi_sendrecv. ** ** Parameters: ** ** mi_bitvarying * Gen_param1; Pointer to the input text. ** MI_FPARAM * Gen_fparam; Standard info - see DBDK docs. ** ** Return value: ** ** mi_sendrecv * The constructed UDT value. ** ** History: ** ** 06/11/1998 - Generated by BladeSmith Version 3.60.TC1B1. ** ** Identification: ** ** Warning: Do not remove or modify this comment: ** Matrix2dSend FunctionId: 851d2d80-5f56-11d0-93a5-00a0c9202325 ** ***************************************************************** */ mi_sendrecv * Matrix2dSend ( mi_bitvarying * Gen_param1, /* The UDT value */ MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs. */ ) { MI_CONNECTION * Gen_Con; /* The current connection. */ Matrix2d * Gen_InData; /* Pointer to the UDT value. */ Matrix2d * Gen_OutData; /* Pointer to the packet data. */ mi_sendrecv * Gen_RetVal; /* The return value. */ mi_integer Gen_vl_nitems; /* Number of items. */ mi_integer Gen_vl_itemno; /* Dummy index. */ mi_integer Gen_vl_len; /* The length. */ /* Get the current connection handle. */ Gen_Con = mi_open( NULL, NULL, NULL ); /* Verify that the connection has been established. */ if( Gen_Con == 0 ) { /* ** Opening the current connection has failed ** so issue the following message and quit. ** ** "Connection has failed in Matrix2dSend." */ DBDK_TRACE_ERROR( "Matrix2dSend", ERRORMESG1, 10 ); /* not reached */ } /* Point to the input data. */ Gen_InData = (Matrix2d *)mi_get_vardata( (mi_lvarchar *)Gen_param1 ); /* Get the length of the data to follow. */ Gen_vl_len = mi_get_varlen( (mi_lvarchar *)Gen_param1 ); /* Compute the number of variable length items. */ Gen_vl_nitems = (Gen_vl_len - offsetof( Matrix2d, data )) / sizeof( Gen_InData->data ); /* Allocate a new return value. */ Gen_RetVal = (mi_sendrecv *)mi_new_var( sizeof( Matrix2d ) + (Gen_vl_nitems - 1) * sizeof( Gen_InData->data )); if( Gen_RetVal == 0 ) { /* ** Memory allocation has failed so issue ** the following message and quit. ** ** "Memory allocation has failed in Matrix2dSend." */ DBDK_TRACE_ERROR( "Matrix2dSend", ERRORMESG2, 10 ); /* not reached */ } /* Point to the output data. */ Gen_OutData = (Matrix2d *)mi_get_vardata( (mi_lvarchar *)Gen_RetVal ); /* ** Handle the fixed elements of the UDT. */ /* Prepare the value for Gen_OutData->noOfRows. */ mi_put_integer( (mi_unsigned_char1 *)&Gen_OutData->noOfRows, Gen_InData->noOfRows ); /* Prepare the value for Gen_OutData->noOfCols. */ mi_put_integer( (mi_unsigned_char1 *)&Gen_OutData->noOfCols, Gen_InData->noOfCols ); /* ** Handle the variable elements of the UDT. */ for( Gen_vl_itemno = 0; Gen_vl_itemno < Gen_vl_nitems; Gen_vl_itemno++ ) { /* Prepare the value for Gen_OutData->data. */ mi_put_double_precision( (mi_unsigned_char1 *)&Gen_OutData->data[Gen_vl_itemno], &Gen_InData->data[Gen_vl_itemno] ); } /* Close the connection. */ mi_close( Gen_Con ); /* Return the UDT for transmission. */ return Gen_RetVal; } /* }}FUNCTION (#BH4163KA) */ /* {{FUNCTION(851d2d81-5f56-11d0-93a5-00a0c9202325) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** Matrix2dReceive ** ** Description: ** ** The binary receive function is used to convert an instance of a ** data type between its internal representation on the server and ** on the client. ** ** Special Comments: ** ** Support routine for opaque type Matrix2d returns mi_bitvarying. ** ** Parameters: ** ** mi_lvarchar * Gen_param1; Pointer to the input text. ** MI_FPARAM * Gen_fparam; Standard info - see DBDK docs. ** ** Return value: ** ** mi_bitvarying * The constructed UDT value. ** ** History: ** ** 06/11/1998 - Generated by BladeSmith Version 3.60.TC1B1. ** ** Identification: ** ** Warning: Do not remove or modify this comment: ** Matrix2dReceive FunctionId: 851d2d81-5f56-11d0-93a5-00a0c9202325 ** ***************************************************************** */ mi_bitvarying * Matrix2dReceive ( mi_sendrecv * Gen_param1, /* The UDT value. */ MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs. */ ) { MI_CONNECTION * Gen_Con; /* The current connection. */ mi_bitvarying * Gen_RetVal; /* The return value. */ Matrix2d * Gen_InData; /* Packet data. */ Matrix2d * Gen_OutData; /* Output UDT value. */ mi_integer Gen_vl_nitems; /* Number of data items. */ mi_integer Gen_vl_itemno; /* Index thru the items. */ mi_integer Gen_vl_len; /* The length. */ /* Get the current connection handle. */ Gen_Con = mi_open( NULL, NULL, NULL ); /* Verify that the connection has been established. */ if( Gen_Con == 0 ) { /* ** Opening the current connection has failed ** so issue the following message and quit. ** ** "Connection has failed in Matrix2dReceive." */ DBDK_TRACE_ERROR( "Matrix2dReceive", ERRORMESG1, 10 ); /* not reached */ } /* Point to the input data. */ Gen_InData = (Matrix2d *)mi_get_vardata( (mi_lvarchar *)Gen_param1 ); /* Get the length of the data to follow. */ Gen_vl_len = mi_get_varlen( (mi_lvarchar *)Gen_param1 ); /* Compute the number of items in the variable length list. */ Gen_vl_nitems = (Gen_vl_len - offsetof( Matrix2d, data )) / sizeof( Gen_OutData->data ); /* Allocate room for the UDT. */ Gen_RetVal = (mi_bitvarying *)mi_new_var( sizeof( Matrix2d ) + (Gen_vl_nitems - 1) * sizeof( Gen_OutData->data )); if( Gen_RetVal == 0 ) { /* ** Memory allocation has failed so issue ** the following message and quit. ** ** "Memory allocation has failed in Matrix2dReceive." */ DBDK_TRACE_ERROR( "Matrix2dReceive", ERRORMESG2, 10 ); /* not reached */ } /* Point to the output data. */ Gen_OutData = (Matrix2d *)mi_get_vardata( (mi_lvarchar *)Gen_RetVal ); /* Copy the attribute value(s) from the transmission parcel. */ /* ** Handle the fixed elements of the UDT. */ /* Prepare the value for Gen_OutData->noOfRows. */ mi_get_integer( (mi_unsigned_char1 *)&Gen_InData->noOfRows, &Gen_OutData->noOfRows ); /* Prepare the value for Gen_OutData->noOfCols. */ mi_get_integer( (mi_unsigned_char1 *)&Gen_InData->noOfCols, &Gen_OutData->noOfCols ); /* ** Handle the variable elements of the UDT. */ for( Gen_vl_itemno = 0; Gen_vl_itemno < Gen_vl_nitems; Gen_vl_itemno++ ) { /* Prepare the value for Gen_OutData->data. */ mi_get_double_precision( (mi_unsigned_char1 *)&Gen_InData->data[Gen_vl_itemno], &Gen_OutData->data[Gen_vl_itemno] ); } /* Return the transmitted UDT value. */ return Gen_RetVal; } /* }}FUNCTION (#EGQ5J1U7) */ /* {{FUNCTION(851d2d92-5f56-11d0-93a5-00a0c9202325) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** Matrix2dCompare ** ** Description: ** ** Perform the comparison operations required to compare two ** UDT values. ** ** This function returns zero if the two UDT values are equal and ** a non-zero value otherwise. ** ** Special Comments: ** ** Compares two variable-length opaque types ** ** Parameters: ** ** mi_bitvarying * Gen_param1; The first UDT value to compare. ** mi_bitvarying * Gen_param2; The second UDT value to compare. ** MI_FPARAM * Gen_fparam; Standard info - see DBDK docs. ** ** Return value: ** ** mi_integer The comparison result. ** ** History: ** ** 06/11/1998 - Generated by BladeSmith Version 3.60.TC1B1. ** ** Identification: ** ** Warning: Do not remove or modify this comment: ** Matrix2dCompare FunctionId: 851d2d92-5f56-11d0-93a5-00a0c9202325 ** ***************************************************************** */ mi_integer Matrix2dCompare ( mi_bitvarying * Gen_param1, /* The first UDT value to compare. */ mi_bitvarying * Gen_param2, /* The second UDT value to compare. */ MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs. */ ) { MI_CONNECTION * Gen_Con; /* The current connection. */ mi_integer Gen_cc; /* Numeric attribute difference. */ Matrix2d * Gen_Value1; /* Pointer to the first value. */ Matrix2d * Gen_Value2; /* Pointer to the second value. */ mi_integer Gen_vl_nitems; /* The number of items. */ mi_integer Gen_vl_itemno; /* Index thru the items. */ mi_integer Gen_vl_len_dif; /* Data length difference. */ /* Get the current connection handle. */ Gen_Con = mi_open( NULL, NULL, NULL ); /* Verify that the connection has been established. */ if( Gen_Con == 0 ) { /* ** Opening the current connection has failed ** so issue the following message and quit. ** ** "Connection has failed in Matrix2dCompare." */ DBDK_TRACE_ERROR( "Matrix2dCompare", ERRORMESG1, 10 ); /* not reached */ } /* Point to the data values that are to be compared. */ Gen_Value1 = (Matrix2d *)mi_get_vardata( (mi_lvarchar *)Gen_param1 ); Gen_Value2 = (Matrix2d *)mi_get_vardata( (mi_lvarchar *)Gen_param2 ); /* Compute the difference of the lengths of the two UDTs. */ Gen_vl_len_dif = mi_get_varlen( (mi_lvarchar *)Gen_param1 ) - mi_get_varlen( (mi_lvarchar *)Gen_param1 ); /* Compute the number of variable length items. */ Gen_vl_nitems = (Gen_vl_len_dif <= 0 ? ( mi_get_varlen( (mi_lvarchar *)Gen_param1) - offsetof( Matrix2d, data )) / sizeof( Gen_Value1->data ) : ( mi_get_varlen( (mi_lvarchar *)Gen_param2 ) - offsetof( Matrix2d, data )) / sizeof( Gen_Value1->data ) ); /* ** Handle the fixed elements of the UDT. */ /* Compare the two values. */ Gen_cc = Gen_Value1->noOfRows - Gen_Value2->noOfRows; if( Gen_cc ) { return Gen_cc < 0 ? -1 : 1; } /* Compare the two values. */ Gen_cc = Gen_Value1->noOfCols - Gen_Value2->noOfCols; if( Gen_cc ) { return Gen_cc < 0 ? -1 : 1; } /* ** Handle the variable elements of the UDT. */ for( Gen_vl_itemno = 0; Gen_vl_itemno < Gen_vl_nitems; Gen_vl_itemno++ ) { /* Compare the two values. */ Gen_cc = Gen_Value1->data[Gen_vl_itemno] > Gen_Value2->data[Gen_vl_itemno] ? +1 : Gen_Value1->data[Gen_vl_itemno] < Gen_Value2->data[Gen_vl_itemno] ? -1 : 0 ; if( Gen_cc ) { return Gen_cc < 0 ? -1 : 1; } } /* Close the connection. */ mi_close( Gen_Con ); return Gen_vl_len_dif < 0 ? -1 : !Gen_vl_len_dif ? 0 : 1; } /* }}FUNCTION (#21HVH1U2) */ /* {{FUNCTION(851d2d84-5f56-11d0-93a5-00a0c9202325) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** Matrix2dEqual ** ** Description: ** ** Determine if one UDT value is equal to another. ** ** Special Comments: ** ** Compares two variable-length opaque types for equality ** ** Parameters: ** ** mi_bitvarying * Gen_param1; The first UDT value to compare. ** mi_bitvarying * Gen_param2; The second UDT value to compare. ** MI_FPARAM * Gen_fparam; Standard info - see DBDK docs. ** ** Return value: ** ** mi_boolean The comparison result. ** ** History: ** ** 06/11/1998 - Generated by BladeSmith Version 3.60.TC1B1. ** ** Identification: ** ** Warning: Do not remove or modify this comment: ** Matrix2dEqual FunctionId: 851d2d84-5f56-11d0-93a5-00a0c9202325 ** ***************************************************************** */ mi_boolean Matrix2dEqual ( mi_bitvarying * Gen_param1, /* The first UDT value to compare. */ mi_bitvarying * Gen_param2, /* The second UDT value to compare. */ MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs. */ ) { /* Call Compare to perform the comparison. */ return (mi_boolean)(0 == Matrix2dCompare( Gen_param1, Gen_param2, Gen_fparam )); } /* }}FUNCTION (#M6A33JU6) */ /* {{FUNCTION(851d2d85-5f56-11d0-93a5-00a0c9202325) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** Matrix2dNotEqual ** ** Description: ** ** Determine if one UDT value is not equal to another. ** ** Special Comments: ** ** Compares two variable-length opaque types for non-equality ** ** Parameters: ** ** mi_bitvarying * Gen_param1; The first UDT value to compare. ** mi_bitvarying * Gen_param2; The second UDT value to compare. ** MI_FPARAM * Gen_fparam; Standard info - see DBDK docs. ** ** Return value: ** ** mi_boolean The comparison result. ** ** History: ** ** 06/11/1998 - Generated by BladeSmith Version 3.60.TC1B1. ** ** Identification: ** ** Warning: Do not remove or modify this comment: ** Matrix2dNotEqual FunctionId: 851d2d85-5f56-11d0-93a5-00a0c9202325 ** ***************************************************************** */ mi_boolean Matrix2dNotEqual ( mi_bitvarying * Gen_param1, /* The first UDT value to compare. */ mi_bitvarying * Gen_param2, /* The second UDT value to compare. */ MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs. */ ) { /* Call Compare to perform the comparison. */ return (mi_boolean)(0 != Matrix2dCompare( Gen_param1, Gen_param2, Gen_fparam )); } /* }}FUNCTION (#8BPS131Q) */ /* {{FUNCTION(851d2d86-5f56-11d0-93a5-00a0c9202325) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** Matrix2dPlus ** ** Description: ** ** Special Comments: ** ** Entrypoint for the SQL routine Plus (Matrix2d,Matrix2d) returns Matrix2d. ** ** Parameters: ** ** Return value: ** ** Matrix2d ** ** History: ** ** 06/30/1998 - Generated by BladeSmith Version 3.60.630 . ** ** Identification: ** ** NOTE: ** ** BladeSmith will add and remove parameters from the function ** prototype, and will generate tracing calls. ONLY EDIT code ** in blocks marked Your_
. Any other modifications ** will require manual merging. ** ***************************************************************** */ UDREXPORT mi_bitvarying * Matrix2dPlus ( Matrix2d * Argument1, Matrix2d * Argument2, MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs.*/ ) { MI_CONNECTION * Gen_Con; /* The connection handle. */ mi_bitvarying * Gen_RetVal; /* The return value wrapper. */ Matrix2d * Gen_OutData; /* The return value. */ /* ------ {{Your_Declarations (PreserveSection) BEGIN ------ */ Matrix2d * _Value1; /* First Matrix */ Matrix2d * _Value2; /* Second Matrix */ mi_integer noOfElements, currElement; /* ------ }}Your_Declarations (#0000) END ------ */ /* Use the NULL connection. */ Gen_Con = NULL; /* ------ {{Your_Code (PreserveSection) BEGIN ------ */ /* ** Write to the trace file indicating ** that Matrix2dPlus has been called. */ DBDK_TRACE_ENTER( "Matrix2dPlus" ); /* Get the Matrix from the input arguments */ _Value1 = (Matrix2d *)mi_get_vardata( (mi_lvarchar *)Argument1 ); _Value2 = (Matrix2d *)mi_get_vardata( (mi_lvarchar *)Argument2 ); /* Check for Null value */ if ((_Value1 == NULL) || (_Value1 == NULL)) { mi_db_error_raise( Gen_Con, MI_SQL, ERRORMESG2, "FUNCTION%s", "Matrix2dPlus", (char *)NULL); /* not reached */ } /* Check matrix are multipliable */ if ( (_Value1->noOfRows != _Value1->noOfRows) || (_Value1->noOfCols != _Value1->noOfCols)) { mi_db_error_raise( Gen_Con, MI_SQL, ERRORMESG2, "FUNCTION%s", "Matrix2dPlus", (char *)NULL); /* not reached */ } /* Compute the number of elements in the result Matrix */ noOfElements = (_Value1->noOfRows)* (_Value1->noOfCols); /* ** Allocate the return value. It must be allo- ** cated if it is a variable length UDT. ** */ Gen_RetVal = (mi_bitvarying *)mi_new_var(sizeof( Matrix2d ) + (noOfElements-1)*sizeof(Gen_OutData->data)); if( Gen_RetVal == 0) { /* ** Memory allocation has failed so issue ** the following message and quit. ** ** "Memory allocation has failed in Matrix2dPlus." */ DBDK_TRACE_ERROR( "Matrix2dPlus", ERRORMESG2, 10 ); /* not reached */ } /* Point to where the return value is to be placed. */ Gen_OutData = (Matrix2d *)mi_get_vardata( (mi_lvarchar *)Gen_RetVal ); Gen_OutData->noOfRows = _Value1->noOfRows; Gen_OutData->noOfCols = _Value1->noOfCols; /* Calculate the sum of two given UDT */ for (currElement = 0; currElement < noOfElements; currElement++) { Gen_OutData->data[currElement] = _Value1->data[currElement] + _Value2->data[currElement]; } /* ** Write to the trace file indicating ** that Matrix2dPlus has successfully exited. */ DBDK_TRACE_EXIT( "Matrix2dPlus" ); /* ------ }}Your_Code (#M2JS) END ------ */ /* Return the function's return value. */ return Gen_RetVal; } /* }}FUNCTION (#O1LMBLG8) */ /* {{FUNCTION(851d2d87-5f56-11d0-93a5-00a0c9202325) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** Matrix2dMinus ** ** Description: ** ** Special Comments: ** ** Entrypoint for the SQL routine Minus (Matrix2d,Matrix2d) returns Matrix2d. ** ** Parameters: ** ** Return value: ** ** Matrix2d ** ** History: ** ** 06/30/1998 - Generated by BladeSmith Version 3.60.630 . ** ** Identification: ** ** NOTE: ** ** BladeSmith will add and remove parameters from the function ** prototype, and will generate tracing calls. ONLY EDIT code ** in blocks marked Your_
. Any other modifications ** will require manual merging. ** ***************************************************************** */ UDREXPORT mi_bitvarying * Matrix2dMinus ( Matrix2d * Argument1, Matrix2d * Argument2, MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs.*/ ) { MI_CONNECTION * Gen_Con; /* The connection handle. */ mi_bitvarying * Gen_RetVal; /* The return value wrapper. */ Matrix2d * Gen_OutData; /* The return value. */ /* ------ {{Your_Declarations (PreserveSection) BEGIN ------ */ Matrix2d * _Value1; /* First Matrix */ Matrix2d * _Value2; /* Second Matrix */ mi_integer noOfElements, currElement; /* ------ }}Your_Declarations (#0000) END ------ */ /* Use the NULL connection. */ Gen_Con = NULL; /* ------ {{Your_Code (PreserveSection) BEGIN ------ */ /* ** Write to the trace file indicating ** that Matrix2dMinus has been called. */ DBDK_TRACE_ENTER( "Matrix2dMinus" ); /* Get the Matrix from the input arguments */ _Value1 = (Matrix2d *)mi_get_vardata( (mi_lvarchar *)Argument1 ); _Value2 = (Matrix2d *)mi_get_vardata( (mi_lvarchar *)Argument2 ); /* Check for Null value */ if ((_Value1 == NULL) || (_Value1 == NULL)) { mi_db_error_raise( Gen_Con, MI_SQL, ERRORMESG2, "FUNCTION%s", "Matrix2dMinus", (char *)NULL); /* not reached */ } /* Check matrix are multipliable */ if ( (_Value1->noOfRows != _Value1->noOfRows) || (_Value1->noOfCols != _Value1->noOfCols)) { mi_db_error_raise( Gen_Con, MI_SQL, ERRORMESG2, "FUNCTION%s", "Matrix2dMinus", (char *)NULL); /* not reached */ } /* Compute the number of elements in the result Matrix */ noOfElements = (_Value1->noOfRows)* (_Value1->noOfCols); /* ** Allocate the return value. It must be allo- ** cated if it is a variable length UDT. ** */ Gen_RetVal = (mi_bitvarying *)mi_new_var(sizeof( Matrix2d ) + (noOfElements-1)*sizeof(Gen_OutData->data)); if( Gen_RetVal == 0) { /* ** Memory allocation has failed so issue ** the following message and quit. ** ** "Memory allocation has failed in Matrix2dMinus." */ DBDK_TRACE_ERROR( "Matrix2dMinus", ERRORMESG2, 10 ); /* not reached */ } /* Point to where the return value is to be placed. */ Gen_OutData = (Matrix2d *)mi_get_vardata( (mi_lvarchar *)Gen_RetVal ); Gen_OutData->noOfRows = _Value1->noOfRows; Gen_OutData->noOfCols = _Value1->noOfCols; /* Calculate the difference of two given UDT */ for (currElement = 0; currElement < noOfElements; currElement++) { Gen_OutData->data[currElement] = _Value1->data[currElement] - _Value2->data[currElement]; } /* ** Write to the trace file indicating ** that Matrix2dMinus has successfully exited. */ DBDK_TRACE_EXIT( "Matrix2dMinus" ); /* ------ }}Your_Code (#CIQ2) END ------ */ /* Return the function's return value. */ return Gen_RetVal; } /* }}FUNCTION (#I73FEE56) */ /* {{FUNCTION(851d2d91-5f56-11d0-93a5-00a0c9202325) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** Matrix2dTimes ** ** Description: ** ** Special Comments: ** ** Entrypoint for the SQL routine Times (Matrix2d,Matrix2d) returns Matrix2d. ** ** Parameters: ** ** Return value: ** ** Matrix2d ** ** History: ** ** 06/30/1998 - Generated by BladeSmith Version 3.60.630 . ** ** Identification: ** ** NOTE: ** ** BladeSmith will add and remove parameters from the function ** prototype, and will generate tracing calls. ONLY EDIT code ** in blocks marked Your_
. Any other modifications ** will require manual merging. ** ***************************************************************** */ UDREXPORT mi_bitvarying * Matrix2dTimes ( Matrix2d * Argument1, Matrix2d * Argument2, MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs.*/ ) { MI_CONNECTION * Gen_Con; /* The connection handle. */ mi_bitvarying * Gen_RetVal; /* The return value wrapper. */ Matrix2d * Gen_OutData; /* The return value. */ /* ------ {{Your_Declarations (PreserveSection) BEGIN ------ */ Matrix2d * _Value1; /* First Matrix */ Matrix2d * _Value2; /* Second Matrix */ mi_integer noOfElements; mi_integer currElement; mi_integer currRow; mi_integer currCol; /* ------ }}Your_Declarations (#0000) END ------ */ /* Use the NULL connection. */ Gen_Con = NULL; /* ------ {{Your_Code (PreserveSection) BEGIN ------ */ /* ** Write to the trace file indicating ** that Matrix2dTimes has been called. */ DBDK_TRACE_ENTER( "Matrix2dTimes" ); /* Get the Matrix from the input arguments */ _Value1 = (Matrix2d *)mi_get_vardata( (mi_lvarchar *)Argument1 ); _Value2 = (Matrix2d *)mi_get_vardata( (mi_lvarchar *)Argument2 ); /* Check for Null value */ if ((_Value1 == NULL) || (_Value1 == NULL)) { mi_db_error_raise( Gen_Con, MI_SQL, ERRORMESG2, "FUNCTION%s", "Matrix2dTimes", (char *)NULL); /* not reached */ } /* Check matrix are multipliable */ if ( (_Value1->noOfRows != _Value1->noOfRows) || (_Value1->noOfCols != _Value1->noOfCols)) { mi_db_error_raise( Gen_Con, MI_SQL, ERRORMESG2, "FUNCTION%s", "Matrix2dTimes", (char *)NULL); /* not reached */ } /* Compute the number of elements in the result Matrix */ noOfElements = (_Value1->noOfRows)* (_Value1->noOfCols); /* ** Allocate the return value. It must be allo- ** cated if it is a variable length UDT. ** */ Gen_RetVal = (mi_bitvarying *)mi_new_var(sizeof( Matrix2d ) + (noOfElements-1)*sizeof(Gen_OutData->data)); if( Gen_RetVal == 0) { /* ** Memory allocation has failed so issue ** the following message and quit. ** ** "Memory allocation has failed in Matrix2dTimes." */ DBDK_TRACE_ERROR( "Matrix2dTimes", ERRORMESG2, 10 ); /* not reached */ } /* Point to where the return value is to be placed. */ Gen_OutData = (Matrix2d *)mi_get_vardata( (mi_lvarchar *)Gen_RetVal ); /* Calculate the result matrix */ Gen_OutData->noOfRows = _Value1->noOfRows; Gen_OutData->noOfCols = _Value1->noOfCols; /* Compute the Multiplication */ currElement = 0; for (currRow = 0; currRow < Gen_OutData->noOfRows; currRow++) { for(currCol =0; currCol < Gen_OutData->noOfCols; currCol++) { mi_integer currSum; Gen_OutData->data[currElement] = 0; for (currSum=0; currSum < _Value1->noOfCols; currSum++) { Gen_OutData->data[currElement] += (_Value1->data[currRow*_Value1->noOfCols+currSum])* (_Value2->data[currSum*_Value2->noOfCols+currCol]); } currElement++; } } /* ** Write to the trace file indicating ** that Matrix2dTimes has successfully exited. */ DBDK_TRACE_EXIT( "Matrix2dTimes" ); /* ------ }}Your_Code (#CEGI) END ------ */ /* Return the function's return value. */ return Gen_RetVal; } /* }}FUNCTION (#973BEE44) */ /* {{FUNCTION(851d2d89-5f56-11d0-93a5-00a0c9202325) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** Matrix2dDivide ** ** Description: ** ** Special Comments: ** ** Entrypoint for the SQL routine Divide (Matrix2d,Matrix2d) returns Matrix2d. ** ** Parameters: ** ** Return value: ** ** Matrix2d ** ** History: ** ** 06/30/1998 - Generated by BladeSmith Version 3.60.630 . ** ** Identification: ** ** NOTE: ** ** BladeSmith will add and remove parameters from the function ** prototype, and will generate tracing calls. ONLY EDIT code ** in blocks marked Your_
. Any other modifications ** will require manual merging. ** ***************************************************************** */ UDREXPORT mi_bitvarying * Matrix2dDivide ( Matrix2d * Argument1, Matrix2d * Argument2, MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs.*/ ) { MI_CONNECTION * Gen_Con; /* The connection handle. */ mi_bitvarying * Gen_RetVal; /* The return value wrapper. */ Matrix2d * Gen_OutData; /* The return value. */ /* ------ {{Your_Declarations (PreserveSection) BEGIN ------ */ Matrix2d * _Value1; /* First Matrix */ Matrix2d * _Value2; /* Second Matrix */ mi_integer noOfElements; mi_integer currElement; mi_integer currRow; mi_integer currCol; /* ------ }}Your_Declarations (#0000) END ------ */ /* Use the NULL connection. */ Gen_Con = NULL; /* ------ {{Your_Code (PreserveSection) BEGIN ------ */ /* ** Write to the trace file indicating ** that Matrix2dDivide has been called. */ DBDK_TRACE_ENTER( "Matrix2dDivide" ); /* Get the Matrix from the input arguments */ _Value1 = (Matrix2d *)mi_get_vardata( (mi_lvarchar *)Argument1 ); _Value2 = (Matrix2d *)mi_get_vardata( (mi_lvarchar *)Argument2 ); /* Check for Null value */ if ((_Value1 == NULL) || (_Value1 == NULL)) { mi_db_error_raise( Gen_Con, MI_SQL, ERRORMESG2, "FUNCTION%s", "Matrix2dDivide", (char *)NULL); /* not reached */ } /* Check matrix are multipliable */ if ( (_Value1->noOfRows != _Value1->noOfRows) || (_Value1->noOfCols != _Value1->noOfCols)) { mi_db_error_raise( Gen_Con, MI_SQL, ERRORMESG2, "FUNCTION%s", "Matrix2dDivide", (char *)NULL); /* not reached */ } /* Compute the number of elements in the result Matrix */ noOfElements = (_Value1->noOfRows)* (_Value1->noOfCols); /* ** Allocate the return value. It must be allo- ** cated if it is a variable length UDT. ** */ Gen_RetVal = (mi_bitvarying *)mi_new_var(sizeof( Matrix2d ) + (noOfElements-1)*sizeof(Gen_OutData->data)); if( Gen_RetVal == 0) { /* ** Memory allocation has failed so issue ** the following message and quit. ** ** "Memory allocation has failed in Matrix2dDivide." */ DBDK_TRACE_ERROR( "Matrix2dDivide", ERRORMESG2, 10 ); /* not reached */ } /* Point to where the return value is to be placed. */ Gen_OutData = (Matrix2d *)mi_get_vardata( (mi_lvarchar *)Gen_RetVal ); /* Calculate the result matrix */ Gen_OutData->noOfRows = _Value1->noOfRows; Gen_OutData->noOfCols = _Value1->noOfCols; /* Compute the Division */ currElement = 0; for (currRow = 0; currRow < Gen_OutData->noOfRows; currRow++) { for(currCol =0; currCol < Gen_OutData->noOfCols; currCol++) { mi_integer currSum; Gen_OutData->data[currElement] = 0; for (currSum=0; currSum < _Value1->noOfCols; currSum++) { Gen_OutData->data[currElement] += (_Value1->data[currRow*_Value1->noOfCols+currSum])/ (_Value2->data[currSum*_Value2->noOfCols+currCol]); } currElement++; } } /* ** Write to the trace file indicating ** that Matrix2dDivide has successfully exited. */ DBDK_TRACE_EXIT( "Matrix2dDivide" ); /* ------ }}Your_Code (#OB8P) END ------ */ /* Return the function's return value. */ return Gen_RetVal; } /* }}FUNCTION (#U9EJ7CMT) */ /* {{FUNCTION(851d2d82-5f56-11d0-93a5-00a0c9202325) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** Matrix2dInput ** ** Description: ** ** This function converts from the external representation of the ** UDT type Matrix2d to its internal representation. ** The external representation is a comma seperated list sourrounded ** by round parenthesis. Each column itself is a comma seperated ** list sourounded by roud parenthesis: ** ((x1,y1),(x2,y2),...) ** The internal representation is a 'C' structure of type Matrix2d as ** defined in the header file. ** ** Data may be inserted into a table using an SQL insert statment: ** ** insert into tablename values ( 'value-list' ); ** ** value-list is a space-delimited list of values. ** ** Special Comments: ** ** Support routine for opaque type Matrix2d. ** ** Parameters: ** ** mi_lvarchar * Gen_param1; Pointer to the input text. ** MI_FPARAM * Gen_fparam; Standard info - see DBDK docs. ** ** Return value: ** ** mi_lvarchar * The constructed UDT value. ** ** History: ** ** Jun 19, 1997 - Generated by BladeSmith Version 3.70.TC1 . ** ** Identification: ** ** Warning: Do not remove or modify this comment: ** Matrix2dInput FunctionId: 851d2d82-5f56-11d0-93a5-00a0c9202325 ** ***************************************************************** */ mi_lvarchar * Matrix2dInput ( mi_lvarchar * Gen_param1, /* Pointer to the input text. */ MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs. */ ) { MI_CONNECTION * Gen_Con; /* The current connection. */ gl_mchar_t * Gen_InData; /* Pointer to the input data. */ gl_mchar_t * Gen_StartInData; /* First value of Gen_InData. */ Matrix2d * Gen_OutData; /* Pointer to the output data. */ mi_integer Gen_DataLen; /* Length of the data in bytes. */ mi_integer Gen_UDTSize; /* Size of the UDT in bytes. */ mi_integer Gen_vl_nitems; /* Number of variable length items.*/ mi_integer Gen_vl_itemno; /* Index through the items. */ mi_lvarchar * Gen_RetVal; /* The return value. */ mi_integer noOfRows; /* Number of rows */ mi_integer noOfCols; /* Number of columns */ char * tempStr; /* Get the current connection handle. */ Gen_Con = mi_open( NULL, NULL, NULL ); /* Verify that the connection has been established. */ if( Gen_Con == 0 ) { /* ** Opening the current connection has failed ** so issue the following message and quit. ** ** "Connection has failed in Matrix2dInput." */ DBDK_TRACE_ERROR( "Matrix2dInput", ERRORMESG1, 10 ); /* not reached */ } /* ** Write to the trace file indicating ** that Matrix2dInput has been called. */ DBDK_TRACE_ENTER( "Matrix2dInput" ); /* Point to the input data. */ Gen_InData = (gl_mchar_t *)mi_get_vardata( Gen_param1 ); Gen_StartInData = Gen_InData; /* Get the length of the input string. */ Gen_DataLen = mi_get_varlen( Gen_param1 ); /* Compute the number of repetitions in the variable length input. */ _noOfRowsAndCols( (char*)Gen_InData, &noOfRows, &noOfCols ); Gen_vl_nitems = noOfRows*noOfCols; /* Compute the amount of memory required for the data. */ Gen_UDTSize = sizeof( Matrix2d ) + (Gen_vl_nitems - 1) * sizeof( Gen_OutData->data ); /* Allocate a new UDT for the return result. */ Gen_RetVal = mi_new_var( Gen_UDTSize ); if( Gen_RetVal == 0 ) { /* ** Memory allocation has failed so issue ** the following message and quit. ** ** "Memory allocation has failed in Matrix2dInput." */ DBDK_TRACE_ERROR( "Matrix2dInput", ERRORMESG2, 10 ); /* not reached */ } /* Point to the output data. */ Gen_OutData = (Matrix2d *)mi_get_vardata( Gen_RetVal ); /* ** Handle the fixed elements of the UDT. */ /* Get the data value for Gen_OutData->noOfRows. */ Gen_OutData->noOfRows = noOfRows; /* Get the data value for Gen_OutData->noOfCols. */ Gen_OutData->noOfCols = noOfCols; /* Handle the variable part of the UDT. */ tempStr = (char *)Gen_InData; for( Gen_vl_itemno = 0; Gen_vl_itemno < Gen_vl_nitems; Gen_vl_itemno++ ) { /* Get the data value for Gen_OutData->data[Gen_vl_itemno]. */ while ( (!isdigit(*tempStr)) && ((*tempStr) != '.') && ((*tempStr) != '+') && ((*tempStr) != '-') ) tempStr++; tempStr = matrix_sscanf( tempStr, " %lG %n", &Gen_OutData->data[Gen_vl_itemno] ); } /* ** Write to the trace file indicating ** that Matrix2dInput has successfully exited. */ DBDK_TRACE_EXIT( "Matrix2dInput" ); /* Close the connection. */ mi_close( Gen_Con ); /* Return the UDT value. */ return Gen_RetVal; } /* }}FUNCTION (#3IND3JVP) */ /* {{FUNCTION(851d2d83-5f56-11d0-93a5-00a0c9202325) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** Matrix2dOutput ** ** Description: ** ** This function converts from the internal representation of the ** UDT type Matrix2d to its external representation. ** The external representation is a comma seperated list sourrounded ** by round parenthesis. Each column itself is a comma seperated ** list sourounded by roud parenthesis: ** ((x1,y1),(x2,y2),...) ** The internal representation is a 'C' structure of type Matrix2d as ** defined in the header file. ** ** Data may be retrieved from a table using an SQL select statment: ** ** select from tablename; ** ** Special Comments: ** ** Support routine for opaque type Matrix2d. ** ** Parameters: ** ** mi_lvarchar * Gen_param1; Pointer to the input text. ** MI_FPARAM * Gen_fparam; Standard info - see DBDK docs. ** ** Return value: ** ** mi_lvarchar * The constructed UDT value. ** ** History: ** ** Jun 19, 1997 - Generated by BladeSmith Version 3.70.TC1 . ** ** Identification: ** ** Warning: Do not remove or modify this comment: ** Matrix2dOutput FunctionId: 851d2d83-5f56-11d0-93a5-00a0c9202325 ** ***************************************************************** */ mi_lvarchar * Matrix2dOutput ( mi_lvarchar * Gen_param1, /* The UDT value. */ MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs. */ ) { MI_CONNECTION * Gen_Con; /* The current connection. */ mi_integer Gen_CharLen; /* Estimate maximum length. */ Matrix2d * Gen_InData; /* Pointer to the input data. */ char * Gen_OutData; /* Pointer to the output data. */ mi_lvarchar * Gen_RetVal; /* The return result. */ mi_integer Gen_DataLen; /* The data length. */ mi_integer Gen_vl_nitems; /* The number of items. */ mi_integer Gen_vl_itemno; /* Index thru the items. */ mi_integer Gen_vl_len; /* The length. */ char * s; mi_integer offset; mi_integer bFirstRow; mi_integer bFirstCol; mi_integer rowNo, colNo; mi_integer numLen; char temp[512]; /* Get the current connection handle. */ Gen_Con = mi_open( NULL, NULL, NULL ); /* Verify that the connection has been established. */ if( Gen_Con == 0 ) { /* ** Opening the current connection has failed ** so issue the following message and quit. ** ** "Connection has failed in Matrix2dOutput." */ DBDK_TRACE_ERROR( "Matrix2dOutput", ERRORMESG1, 10 ); /* not reached */ } /* ** Write to the trace file indicating ** that Matrix2dOutput has been called. */ DBDK_TRACE_ENTER( "Matrix2dOutput" ); /* Compute the number of variable length items. */ Gen_vl_nitems = (mi_get_varlen( (mi_lvarchar *)Gen_param1 ) - sizeof( Matrix2d ) + sizeof( Gen_InData->data )) / sizeof( Gen_InData->data ); /* Compute the maximum length of the text representation. */ Gen_CharLen = 1; /* Leave room for the NULL terminator. */ Gen_CharLen += 12; /* Add the length for Gen_OutData->noOfRows. */ Gen_CharLen += 12; /* Add the length for Gen_OutData->noOfCols. */ /* Compute the text length for the variable part. */ for( Gen_vl_itemno = 0; Gen_vl_itemno < Gen_vl_nitems; Gen_vl_itemno++ ) { Gen_CharLen += 61; /* Add the length for Gen_OutData->data[Gen_vl_itemno]. */ } /* Allocate room for the output string. */ Gen_RetVal = mi_new_var( Gen_CharLen ); if( Gen_RetVal == 0 ) { /* ** Memory allocation has failed so issue ** the following message and quit. ** ** "Memory allocation has failed in Matrix2dOutput." */ DBDK_TRACE_ERROR( "Matrix2dOutput", ERRORMESG2, 10 ); /* not reached */ } /* Point to the input data. */ Gen_InData = (Matrix2d *)mi_get_vardata( Gen_param1 ); /* Point to the output data. */ Gen_vl_nitems = Gen_InData->noOfRows * Gen_InData->noOfCols; /* Compute the maximum length of the text representation. */ Gen_CharLen = 1; /* Leave room for the NULL terminator. */ /* Outer parens */ Gen_CharLen += 2; /* Parens and commas for delimiting rows */ Gen_CharLen += (2*Gen_InData->noOfRows) + Gen_InData->noOfRows - 1; /* Commas for delimiting columns */ Gen_CharLen += Gen_InData->noOfRows * Gen_InData->noOfCols - 1; /* Elements */ Gen_CharLen += MATRIX_MAX_NUM_SIZE*Gen_vl_nitems; /* Allocate room for the output string. */ Gen_RetVal = mi_new_var( Gen_CharLen ); if( Gen_RetVal == 0 ) { /* ** Memory allocation has failed so issue ** the following message and quit. ** ** "Memory allocation has failed in Matrix2dOutput." */ mi_db_error_raise( Gen_Con, MI_SQL, ERRORMESG2, "FUNCTION%s", "Matrix2dOutput", (char *)NULL ); /* not reached */ } /* Point to the output data. */ Gen_OutData = mi_get_vardata( Gen_RetVal ); s = Gen_OutData; offset = 0; /* opening parens */ s[offset++] = '('; for( rowNo=0, bFirstRow = 1, Gen_vl_itemno=0; rowNo < Gen_InData->noOfRows; rowNo++ ) { if (bFirstRow) bFirstRow = 0; else s[offset++] = ','; s[offset++] = '('; for( colNo=0, bFirstCol=1; colNo < Gen_InData->noOfCols; colNo++ ) { if (bFirstCol) bFirstCol = 0; else s[offset++] = ','; sprintf( temp, "%.16lG", Gen_InData->data[Gen_vl_itemno++]); numLen = strlen( temp ); if (numLen > MATRIX_MAX_NUM_SIZE) dbException("Input number too large"); strncpy(&(s[offset]), temp, numLen); offset += numLen; } s[offset++] = ')'; } /* closing parens */ s[offset++] = ')'; for (;offset < Gen_CharLen; offset++) s[offset] = '\0'; /* ** Place the length of the data ** in the return structure. */ mi_set_varlen ( Gen_RetVal, Gen_CharLen ); /* ** Write to the trace file indicating ** that Matrix2dOutput has successfully exited. */ DBDK_TRACE_EXIT( "Matrix2dOutput" ); /* Close the connection. */ mi_close( Gen_Con ); /* Return the UDT value. */ return Gen_RetVal; } /* }}FUNCTION (#M66MKOH3) */ #ifdef __cplusplus } #endif