42 #if defined __cplusplus
49 static int toData( statusMessageReporting *smr, xDataType *xDT, xData_attributionList *attributes,
const char *text );
50 static char *
toString( statusMessageReporting *smr, xDataType *xDT );
51 static int release( statusMessageReporting *smr, xDataType *xDT );
57 xDataType *xDT = &(element->xDataTypeInfo);
59 xDT->status = xData_xDataType_Ok;
60 xDT->typeString = xData_matrix_ID;
61 xDT->element = element;
88 xDataType *xDT = &(element->xDataTypeInfo);
89 xData_matrix *oldMatrix = (xData_matrix *) xDT->data, *newMatrix;
93 n = oldMatrix->rows * oldMatrix->columns;
94 if( ( newMatrix = (xData_matrix *) xData_malloc2( smr,
sizeof( xData_matrix ) + xDT->length *
sizeof( xData_matrix_rowStartEnd ) +
95 n *
sizeof(
double ), 0,
"data" ) ) == NULL )
return( NULL );
96 newMatrix->rows = oldMatrix->rows;
97 newMatrix->columns = oldMatrix->columns;
98 newMatrix->rowStartEnds = (xData_matrix_rowStartEnd *) &(newMatrix[1]);
99 newMatrix->values = (
double *) &(newMatrix->rowStartEnds[xDT->length]);
100 for( i = 0; i < xDT->length; i++ ) newMatrix->rowStartEnds[i] = oldMatrix->rowStartEnds[i];
101 for( i = 0, oldP = oldMatrix->values, newP = newMatrix->values; i < n; i++, oldP++, newP++ ) *newP = *oldP;
115 static int toData( statusMessageReporting *smr, xDataType *xDT, xData_attributionList *attributes,
const char *text ) {
117 xData_Int i, j, row, start, end, rows, columns, status = 0;
119 const char *
s, *size;
121 xData_matrix *matrix;
128 smrUser, __FILE__, __LINE__, 1,
"xData missing \"size\" attribute" ) );
130 while( isspace( *e ) ) e++;
132 smr_setMessageError( smr, smrUser, __FILE__, __LINE__, 1,
"matrix size attribute missing \",\" separator" );
135 s = (
const char *) ++e;
137 if( ( xDT->data = (xData_matrix *) xData_malloc2( NULL,
sizeof( xData_matrix ) + xDT->length *
sizeof( xData_matrix_rowStartEnd ) +
138 rows * columns *
sizeof(
double ), 0,
"xDT->data" ) ) == NULL )
return( 1 );
139 matrix = (xData_matrix *) xDT->data;
141 matrix->columns = columns;
142 matrix->rowStartEnds = (xData_matrix_rowStartEnd *) &(matrix[1]);
143 matrix->values = (
double *) &(matrix->rowStartEnds[xDT->length]);
145 for( i = 0, s = text; i < xDT->length; i++ ) {
147 if( ( row < 0 ) || ( row >= rows ) ) {
149 smr_setMessageError( smr, smrUser, __FILE__, __LINE__, 1,
"row = %lld out-of-range (valid range is 0 <= row <= %lld)", row, rows );
153 if( ( start < 0 ) || ( start > columns ) ) {
155 smr_setMessageError( smr, smrUser, __FILE__, __LINE__, 1,
"start = %lld out-of-range (valid range is 0 <= start <= %lld)", start, columns );
159 if( ( end < start ) || ( end > columns ) ) {
161 smr_setMessageError( smr, smrUser, __FILE__, __LINE__, 1,
"end = %lld out-of-range (valid range is %lld <= end <= %lld)", end, start, columns );
164 matrix->rowStartEnds[i].row = row;
165 matrix->rowStartEnds[i].start = start;
166 matrix->rowStartEnds[i].end = end;
167 p = &(matrix->values[row * columns]);
168 for( j = 0; j < start; j++ ) *(p++) = 0.;
169 for( s = e; j < end; j++, p++, s = e ) {
172 if( status != 0 )
break;
173 for( ; j < columns; j++ ) *(p++) = 0.;
176 while( isspace( *e ) ) e++;
178 smr_setMessageError( smr, smrUser, __FILE__, __LINE__, 1,
"matrix contains extra data = %s", e );
182 if( status != 0 )
release( smr, xDT );
189 static char *
toString( statusMessageReporting *, xDataType *xDT ) {
191 xData_Int i,
n = 1, start, end, iRow, iColumn;
193 xData_matrix *matrix = (xData_matrix *) xDT->data;
196 for( iRow = 0; iRow < matrix->rows; iRow++ ) {
197 row = &(matrix->values[iRow * matrix->columns]);
198 for( iColumn = 0; iColumn < matrix->columns; iColumn++ )
if( row[iColumn] != 0. )
break;
200 for( end = iColumn; iColumn < matrix->columns; iColumn++ )
if( row[iColumn] != 0. ) end = iColumn + 1;
201 if( start < end ) n += 10 * 3 + 17 * ( end - start + 1 );
203 if( ( str = (
char *) xData_malloc2( NULL, n, 0,
"str" ) ) == NULL )
return( NULL );
204 for( iRow = 0, p = str; iRow < matrix->rows; iRow++ ) {
205 row = &(matrix->values[iRow * matrix->columns]);
206 for( iColumn = 0; iColumn < matrix->columns; iColumn++ )
if( row[iColumn] != 0. )
break;
208 for( end = iColumn; iColumn < matrix->columns; iColumn++ )
if( row[iColumn] != 0. ) end = iColumn + 1;
210 sprintf( p,
"%3d %3d %3d", iRow, start, end );
212 for( i = start; i < end; i++, p += 17 ) sprintf( p,
" %16.9e", row[i] );
223 static int release( statusMessageReporting *smr, xDataType *xDT ) {
225 if( xDT->data != NULL ) xDT->data =
xData_free( smr, xDT->data );
226 return( xDT->status = xData_xDataType_Ok );
231 int getRowStartEndAtIndex( statusMessageReporting *smr, xDataType *xDT, xData_Int index, xData_Int *row, xData_Int *start, xData_Int *end ) {
234 xData_matrix *matrix = (xData_matrix *) xDT->data;
237 if( ( index < 0 ) || ( index >= xDT->length ) ) {
239 "index = %lld out of range (valid range 0 <= index < %lld)", index, xDT->length );
242 *row = matrix->rowStartEnds[index].row;
243 *start = matrix->rowStartEnds[index].start;
244 *end = matrix->rowStartEnds[index].end;
249 #if defined __cplusplus
int xData_stringTo_xData_Int(statusMessageReporting *smr, void *smrUserInterface, char const *c, xData_Int *value, char const *endings, char **e)
int getRowStartEndAtIndex(statusMessageReporting *smr, xDataType *xDT, xData_Int index, xData_Int *row, xData_Int *start, xData_Int *end)
int xData_xDataTypeConvertAttributes(statusMessageReporting *smr, xData_element *element)
int smr_setMessageError(statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt,...)
char * xData_getAttributesValue(xData_attributionList *attributes, const char *name)
static int toData(statusMessageReporting *smr, xDataType *xDT, xData_attributionList *attributes, const char *text)
xData_matrix * xData_matrix_copyData(statusMessageReporting *smr, xData_element *element)
int xData_is_matrix(statusMessageReporting *smr, xDataType *xDT, int setMsg)
int xData_is_xDataType(statusMessageReporting *smr, xDataType *xDT, char const *const type, int setMsg)
int xData_isElement_matrix(statusMessageReporting *smr, xData_element *element, int setMsg)
void * xData_free(statusMessageReporting *, void *p)
int xData_stringTo_double(statusMessageReporting *smr, void *smrUserInterface, char const *c, double *value, char const *endings, char **e)
void * xData_get_smrUserInterfaceFromElement(xData_element *element)
int xData_init_matrix(statusMessageReporting *smr, xData_element *element)
static int release(statusMessageReporting *smr, xDataType *xDT)
int xData_setMessageError_ReturnInt(int value, statusMessageReporting *smr, void *userInterface, const char *packageName, int lineNumber, int code, const char *fmt,...)
static char * toString(statusMessageReporting *smr, xDataType *xDT)
int xData_matrix_free_copyData(statusMessageReporting *smr, void *data)