void dreadrb_dist(int iam, FILE *fp, int_t *nrow, int_t *ncol, int_t *nonz, double **nzval, int_t **rowind, int_t **colptr) { register int_t i, numer_lines = 0; int_t tmp, colnum, colsize, rownum, rowsize, valnum, valsize; char buf[100], type[4]; int sym; /* Line 1 */ fgets(buf, 100, fp); fputs(buf, stdout); /* Line 2 */ for (i=0; i<4; i++) { fscanf(fp, "%14c", buf); buf[14] = 0; tmp = atoi(buf); /*sscanf(buf, "%d", &tmp);*/ if (i == 3) numer_lines = tmp; } DumpLine(fp); /* Line 3 */ fscanf(fp, "%3c", type); fscanf(fp, "%11c", buf); /* pad */ type[3] = 0; #if (DEBUGlevel >= 1) if ( !iam ) printf("Matrix type %s\n", type); #endif fscanf(fp, "%14c", buf); *nrow = atoi(buf); fscanf(fp, "%14c", buf); *ncol = atoi(buf); fscanf(fp, "%14c", buf); *nonz = atoi(buf); fscanf(fp, "%14c", buf); tmp = atoi(buf); if (tmp != 0) if ( !iam ) printf("This is not an assembled matrix!\n"); if (*nrow != *ncol) if ( !iam ) printf("Matrix is not square.\n"); DumpLine(fp); /* Allocate storage for the three arrays ( nzval, rowind, colptr ) */ dallocateA_dist(*ncol, *nonz, nzval, rowind, colptr); /* Line 4: format statement */ fscanf(fp, "%16c", buf); ParseIntFormat(buf, &colnum, &colsize); fscanf(fp, "%16c", buf); ParseIntFormat(buf, &rownum, &rowsize); fscanf(fp, "%20c", buf); ParseFloatFormat(buf, &valnum, &valsize); DumpLine(fp); #if (DEBUGlevel >= 1) if ( !iam ) { printf(IFMT " rows, " IFMT " nonzeros\n", *nrow, *nonz); printf("colnum " IFMT ", colsize " IFMT "\n", colnum, colsize); printf("rownum " IFMT ", rowsize " IFMT "\n", rownum, rowsize); printf("valnum " IFMT ", valsize " IFMT "\n", valnum, valsize); } #endif ReadVector(fp, *ncol+1, *colptr, colnum, colsize); ReadVector(fp, *nonz, *rowind, rownum, rowsize); if ( numer_lines ) { dReadValues(fp, *nonz, *nzval, valnum, valsize); } sym = (type[1] == 'S' || type[1] == 's'); if ( sym ) { FormFullA(*ncol, nonz, nzval, rowind, colptr); } fclose(fp); }
void zreadhb_dist(int iam, FILE *fp, int_t *nrow, int_t *ncol, int_t *nonz, doublecomplex **nzval, int_t **rowind, int_t **colptr) { register int_t i, numer_lines, rhscrd = 0; int_t tmp, colnum, colsize, rownum, rowsize, valnum, valsize; char buf[100], type[4]; #if ( DEBUGlevel>=1 ) CHECK_MALLOC(0, "Enter zreadhb_dist()"); #endif /* Line 1 */ fgets(buf, 100, fp); /* Line 2 */ for (i=0; i<5; i++) { fscanf(fp, "%14c", buf); buf[14] = 0; tmp = atoi(buf); /*sscanf(buf, "%d", &tmp);*/ if (i == 3) numer_lines = tmp; if (i == 4 && tmp) rhscrd = tmp; } DumpLine(fp); /* Line 3 */ fscanf(fp, "%3c", type); fscanf(fp, "%11c", buf); /* pad */ type[3] = 0; #if ( DEBUGlevel>=1 ) if ( !iam ) printf("Matrix type %s\n", type); #endif fscanf(fp, "%14c", buf); *nrow = atoi(buf); fscanf(fp, "%14c", buf); *ncol = atoi(buf); fscanf(fp, "%14c", buf); *nonz = atoi(buf); fscanf(fp, "%14c", buf); tmp = atoi(buf); if (tmp != 0) if ( !iam ) printf("This is not an assembled matrix!\n"); if (*nrow != *ncol) if ( !iam ) printf("Matrix is not square.\n"); DumpLine(fp); /* Allocate storage for the three arrays ( nzval, rowind, colptr ) */ zallocateA_dist(*ncol, *nonz, nzval, rowind, colptr); /* Line 4: format statement */ fscanf(fp, "%16c", buf); ParseIntFormat(buf, &colnum, &colsize); fscanf(fp, "%16c", buf); ParseIntFormat(buf, &rownum, &rowsize); fscanf(fp, "%20c", buf); ParseFloatFormat(buf, &valnum, &valsize); fscanf(fp, "%20c", buf); DumpLine(fp); /* Line 5: right-hand side */ if ( rhscrd ) DumpLine(fp); /* skip RHSFMT */ #if ( DEBUGlevel>=1 ) if ( !iam ) { printf(IFMT " rows, " IFMT " nonzeros\n", *nrow, *nonz); printf("colnum " IFMT ", colsize " IFMT "\n", colnum, colsize); printf("rownum " IFMT ", rowsize " IFMT "\n", rownum, rowsize); printf("valnum " IFMT ", valsize " IFMT "\n", valnum, valsize); } #endif ReadVector(fp, *ncol+1, *colptr, colnum, colsize); #if ( DEBUGlevel>=1 ) if ( !iam ) printf("read colptr[" IFMT "] = " IFMT "\n", *ncol, (*colptr)[*ncol]); #endif ReadVector(fp, *nonz, *rowind, rownum, rowsize); #if ( DEBUGlevel>=1 ) if ( !iam ) printf("read rowind[" IFMT "] = " IFMT "\n", *nonz-1, (*rowind)[*nonz-1]); #endif if ( numer_lines ) { zReadValues(fp, *nonz, *nzval, valnum, valsize); } fclose(fp); #if ( DEBUGlevel>=1 ) CHECK_MALLOC(0, "Exit zreadhb_dist()"); #endif }
SMatrix ReadSparse(char *name, char *probName) { FILE *fp; long n, m, i, j; long n_rows, tmp; long numer_lines; long colnum, colsize, rownum, rowsize; char buf[100], type[4]; SMatrix M, F; if (!name || name[0] == 0) { fp = stdin; } else { fp = fopen(name, "r"); } if (!fp) { Error("Error opening file\n"); } fscanf(fp, "%72c", buf); fscanf(fp, "%8c", probName); probName[8] = 0; DumpLine(fp); for (i=0; i<5; i++) { fscanf(fp, "%14c", buf); sscanf(buf, "%ld", &tmp); if (i == 3) numer_lines = tmp; } DumpLine(fp); fscanf(fp, "%3c", type); type[3] = 0; if (!(type[0] != 'C' && type[1] == 'S' && type[2] == 'A')) { fprintf(stderr, "Wrong type: %s\n", type); exit(0); } fscanf(fp, "%11c", buf); /* pad */ fscanf(fp, "%14c", buf); sscanf(buf, "%ld", &n_rows); fscanf(fp, "%14c", buf); sscanf(buf, "%ld", &n); fscanf(fp, "%14c", buf); sscanf(buf, "%ld", &m); fscanf(fp, "%14c", buf); sscanf(buf, "%ld", &tmp); if (tmp != 0) printf("This is not an assembled matrix!\n"); if (n_rows != n) printf("Matrix is not symmetric\n"); DumpLine(fp); fscanf(fp, "%16c", buf); ParseIntFormat(buf, &colnum, &colsize); fscanf(fp, "%16c", buf); ParseIntFormat(buf, &rownum, &rowsize); fscanf(fp, "%20c", buf); fscanf(fp, "%20c", buf); DumpLine(fp); /* format statement */ M = NewMatrix(n, m, 0); ReadVector(fp, n+1, M.col, colnum, colsize); ReadVector(fp, m, M.row, rownum, rowsize); for (i=0; i<numer_lines; i++) /* dump numeric values */ DumpLine(fp); for (i=0; i<n; i++) ISort(M, i); for (i=0; i<=n; i++) M.startrow[i] = M.col[i]; fclose(fp); F = LowerToFull(M); maxm = 0; for (i=0; i<n; i++) if (F.col[i+1]-F.col[i] > maxm) maxm = F.col[i+1]-F.col[i]; if (F.nz) { for (j=0; j<n; j++) for (i=F.col[j]; i<F.col[j+1]; i++) F.nz[i] = Value(F.row[i], j); } FreeMatrix(M); return(F); }