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; }
140 fprintf(
fp,
"MaxDimensions: %d by %d\n",
A->max_m,
A->max_n);
141 fprintf(
fp,
"flag_col = %d, flag_diag = %d\n",
A->flag_col,
A->flag_diag);
142 fprintf(
fp,
"start_row @ 0x%p:\n",(
A->start_row));
143 for (
j = 0;
j <
A->n;
j++ )
150 fprintf(
fp,
"start_idx @ 0x%p:\n",(
A->start_idx));
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;
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 );
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++ )
273 A->start_row[
i] = -1;
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 )
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;
#define error(err_num, fn_name)
#define mem_bytes(type, old_size, new_size)
int const size_t const size_t n
static char scratch[MAXLINE+1]
SPMAT * sp_get(int m, int n, int maxlen)
int sprow_idx(SPROW *, int)
void sp_dump(FILE *fp, SPMAT *A)
static char line[MAXLINE]
SPMAT * sp_finput(FILE *fp)
void sp_foutput(FILE *fp, SPMAT *A)