1 #include <../../nrnconf.h> 36 static char rcsid[] =
"sparseio.c,v 1.1 1997/12/04 17:55:49 hines Exp";
60 if ( ! (rows=A->
row) )
66 for ( i = 0; i < m; i++ )
69 if ( ! (elts=rows[i].elt) )
71 fprintf(
fp,
"*** NULL element list ***\n");
74 for ( j_idx = 0; j_idx < rows[
i].
len; j_idx++ )
76 fprintf(
fp,
"%d:%-20.15g ",elts[j_idx].col,
78 if ( j_idx % 3 == 2 && j_idx != rows[i].len-1 )
137 {
fprintf(
fp,
"*** NULL ***\n");
return; }
143 for ( j = 0; j < A->
n; j++ )
151 for ( j = 0; j < A->
n; j++ )
160 {
fprintf(
fp,
"*** NULL row ***\n");
return; }
162 for ( i = 0; i < A->
m; i++ )
164 fprintf(
fp,
"row %d: len = %d, maxlen = %d, diag idx = %d\n",
165 i,rows[i].len,rows[i].maxlen,rows[i].
diag);
166 fprintf(
fp,
"element list @ 0x%p\n",(rows[i].elt));
169 fprintf(
fp,
"*** NULL element list ***\n");
173 for ( j_idx = 0; j_idx < rows[
i].
len; j_idx++, elts++ )
174 fprintf(
fp,
"Col: %d, Val: %g, nxt_row = %d, nxt_idx = %d\n",
180 #define MAXSCRATCH 100 189 int col, curr_col, m,
n, tmp, tty;
198 scratch[i].nxt_row = scratch[i].nxt_idx = -1;
200 tty = isatty(fileno(
fp));
204 fprintf(stderr,
"SparseMatrix: ");
206 fprintf(stderr,
"input rows cols: ");
209 }
while ( sscanf(
line,
"%u %u",&m,&n) != 2 );
213 for ( i = 0; i < m; i++ )
216 fprintf(stderr,
"Enter <col> <val> or 'e' to end row\n");
221 fprintf(stderr,
"Entry %d: ",len);
227 }
while ( sscanf(
line,
"%u %lf",&col,&val) != 2 ||
229 }
while ( sscanf(
line,
"%u %f",&col,&val) != 2 ||
231 col >= n || col <= curr_col );
236 scratch[len].
col = col;
263 if (fscanf(
fp,
"SparseMatrix:") == EOF) {
267 if ( (ret_val=fscanf(
fp,
"%u by %u",&m,&
n)) != 2 )
272 for (
i = 0;
i < A->
n;
i++ )
281 if ( (ret_val=fscanf(
fp,
"row %d :",&tmp)) != 1 ||
289 if ( (ret_val=fscanf(
fp,
"%u : %lf",&col,&
val)) != 2 )
291 if ( (ret_val=fscanf(
fp,
"%u : %f",&col,&
val)) != 2 )
294 if ( col <= curr_col || col >=
n )
295 error(E_FORMAT,
"sp_finput");
299 if ( ret_val == EOF )
302 if ( len > rows[
i].maxlen )
304 rows[
i].elt = (
row_elt *)realloc((
char *)rows[
i].elt,
306 rows[
i].maxlen = len;
static char line[MAXLINE]
void sp_foutput(FILE *fp, SPMAT *A)
int const size_t const size_t n
#define mem_bytes(type, old_size, new_size)
int sprow_idx(SPROW *, int)
SPMAT * sp_get(int m, int n, int maxlen)
void sp_dump(FILE *fp, SPMAT *A)
fprintf(stderr, "Don't know the location of params at %p\, pp)
static char scratch[MAXLINE+1]
SPMAT * sp_finput(FILE *fp)
#define error(err_num, fn_name)