/*! \file Copyright (c) 2003, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from U.S. Dept. of Energy) All rights reserved. The source code is distributed under BSD license, see the file License.txt at the top-level directory. */ /* * -- SuperLU MT routine (version 3.0) -- * Lawrence Berkeley National Lab, Univ. of California Berkeley, * and Xerox Palo Alto Research Center. * September 10, 2007 * */ #include #include #include #include "slu_mt_cdefs.h" /* Eat up the rest of the current line */ int_t cDumpLine(FILE *fp) { register int_t c; while ((c = fgetc(fp)) != '\n') ; return 0; } int_t cParseIntFormat(char *buf, int_t *num, int_t *size) { char *tmp; tmp = buf; while (*tmp++ != '(') ; *num = atoi(tmp); while (*tmp != 'I' && *tmp != 'i') ++tmp; ++tmp; *size = atoi(tmp); return 0; } int_t cParseFloatFormat(char *buf, int_t *num, int_t *size) { char *tmp, *period; tmp = buf; while (*tmp++ != '(') ; *num = atoi(tmp); /*sscanf(tmp, "%d", num);*/ while (*tmp != 'E' && *tmp != 'e' && *tmp != 'D' && *tmp != 'd' && *tmp != 'F' && *tmp != 'f') { /* May find kP before nE/nD/nF, like (1P6F13.6). In this case the num picked up refers to P, which should be skipped. */ if (*tmp=='p' || *tmp=='P') { ++tmp; *num = atoi(tmp); /*sscanf(tmp, "%d", num);*/ } else { ++tmp; } } ++tmp; period = tmp; while (*period != '.' && *period != ')') ++period ; *period = '\0'; *size = atoi(tmp); /*sscanf(tmp, "%2d", size);*/ return 0; } int_t cReadVector(FILE *fp, int_t n, int_t *where, int_t perline, int_t persize) { register int_t i, j, item; char tmp, buf[100]; i = 0; while (i < n) { fgets(buf, 100, fp); /* read a line at a time */ for (j=0; j=1 ) 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) printf("This is not an assembled matrix!\n"); if (*nrow != *ncol) printf("Matrix is not square.\n"); cDumpLine(fp); /* Line 4: format statement */ fscanf(fp, "%16c", buf); cParseIntFormat(buf, &colnum, &colsize); fscanf(fp, "%16c", buf); cParseIntFormat(buf, &rownum, &rowsize); fscanf(fp, "%20c", buf); cParseFloatFormat(buf, &valnum, &valsize); fscanf(fp, "%20c", buf); cDumpLine(fp); /* Line 5: right-hand side */ if ( rhscrd ) cDumpLine(fp); /* skip RHSFMT */ #if ( DEBUGlevel>=1 ) printf("%d rows, %d nonzeros\n", *nrow, *nonz); printf("colnum %d, colsize %d\n", colnum, colsize); printf("rownum %d, rowsize %d\n", rownum, rowsize); printf("valnum %d, valsize %d\n", valnum, valsize); #endif /* Allocate storage for the three arrays ( nzval, rowind, colptr ) */ callocateA(*ncol, *nonz, nzval, rowind, colptr); cReadVector(fp, *ncol+1, *colptr, colnum, colsize); cReadVector(fp, *nonz, *rowind, rownum, rowsize); if ( numer_lines ) { cReadValues(fp, *nonz, *nzval, valnum, valsize); } fclose(fp); }