37 #include <sys/types.h>
40 static char *
skip(
char * line ){
41 while (isspace( * line )) line ++;
54 memset( dmatrix, 0,
sizeof(dmatrix) );
55 fp = fopen( filename,
"r" );
57 perror(
"Matrix - Error opening file:" );
61 while ( !count && fgets( line,
sizeof( line ), fp ) ){
63 while ( (pline =
skip( pline )) ){
65 if ( *pline==
'#' || !*pline )
67 if ( *pline<'A' || *pline>
'Z'){
68 error(
"Matrix: Invalid matrix desciption (Character expected in the caption line)" );
70 topChar[ count++ ] = (char)*pline-
'A';
75 while ( fgets( line,
sizeof( line ), fp ) ){
76 char * pline =
skip( line );
78 char leftChar = (char)*pline-
'A';
80 if ( *pline==
'#' || !*pline )
continue;
81 if ( *pline<'A' || *pline>
'Z'){
82 error(
"Matrix: Invalid matrix desciption (Character expected at the beginning of the line)" );
85 for( i=0; i<count; i++ ){
86 pline =
skip( pline+1 );
87 if (!isdigit( *pline ) && *pline!=
'-' && *pline!=
'.'){
88 error(
"Matrix: Excepted a matrix value got '%c'", *pline );
90 dmatrix[ (int)leftChar ][ (
int)topChar[ i ] ] = strtod( pline, &pline );
103 memset( sbmatrix, 0,
sizeof(sbmatrix) );
104 fp = fopen( filename,
"r" );
106 perror(
"Matrix - Error opening file:" );
110 while ( !count && fgets( line,
sizeof( line ), fp ) ){
112 while ( (pline =
skip( pline )) ){
114 if ( *pline==
'#' || !*pline )
116 if ( *pline<'A' || *pline>
'Z'){
117 error(
"Matrix: Invalid matrix desciption (Character expected in the caption line)" );
119 topChar[ count++ ] = (char)*pline-
'A';
124 while ( fgets( line,
sizeof( line ), fp ) ){
125 char * pline =
skip( line );
127 char leftChar = (char)*pline-
'A';
129 if ( *pline==
'#' || !*pline )
continue;
130 if ( *pline<'A' || *pline>
'Z'){
131 error(
"Matrix: Invalid matrix desciption (Character expected at the beginning of the line)" );
134 for( i=0; i<count; i++ ){
135 pline =
skip( pline+1 );
136 if (!isdigit( *pline ) && *pline!=
'-' && *pline!=
'.'){
137 error(
"Matrix: Excepted a matrix value got '%c'", *pline );
139 sbmatrix[ (int)leftChar ][ (
int)topChar[ i ] ] = strtol( pline, &pline, 10 );
150 double val = dmatrix[i][j]*factor;
151 if ((int8_t)val < val)
152 dmatrix[i][j] = (int8_t)val + 1;
154 dmatrix[i][j] = (int8_t)val;
163 return 256.0/threshold;