/* Read a matrix in from FileName structure definition is in SparseMatrix.h */ #include "SparseMatrix.h" #define MaxRows 100 #define MaxNonZero 20 void ReadSparseMatrix(char FileName[],SparseMatrix *mat) { FILE *FilePointer; SparseRow NewRow; int m,n,i[2],j[2]; float value; float matTemp[MaxRows][MaxNonZero]; int jTemp[MaxRows][MaxNonZero]; int Counts[MaxRows]; /* File Operations */ FilePointer = fopen(FileName,"r"); if(FilePointer==NULL) { printf(stderr,"ReadSparseMatrix %s: File problem\n",FileName); } /* Checks file header is appropriate. NOTE: currently assumes float! */ i=fscanf(FilePointer,"5903SparseMatrix %i %i float",&m,&n); if(i!=2){ printf(stderr,"ReadSparseMatrix %s: File problem\n",FileName); } /* Assigns dimensions to matrix pointer */ (*mat).m = m; (*mat).n = n; /* Assigning RowPointer */ (*mat).RowPointer = (SparseRow *) malloc(m*sizeof(SparseRow *)); /* Reads through the file counting and storing the nonzero entries */ /* Limits are defined above by the dimensions of zVals, jVals, and Counts */ i[0] = i[1] = j[0] = j[1] = 0; while(fscanf(FilePointer,"%i\t%i\t%f",&i[1],&j[1],&value)==3) { if((10*i[0]+j[0])<=(10*i[1]+j[1])) { matTemp[i[1]][Counts[i[1]]]=value; jTemp[i[1]][Counts[i[1]]]=j; Counts[i[1]]++; } else { printf(stderr,"ReadSparseMatrix %s: File problem\n",FileName); return; } i[0] = i[1]; j[0] = j[1]; } /* Closes File */ fclose(FilePointer); /* Assigning Rows */ for(i=0;i