|
depending on the Matrix Market format indicated by | coordinate (coordinate sparse storage) |
|
depending on the Matrix Market format indicated by or | array (dense array storage). The data will be duplicated % as appropriate if symmetry is indicated in the header. % % Optionally |
|
| if (mmfile==-1) disp(filename) |
|
| error ('File not found') |
|
| if (length(symm)==0) disp(['Not enough words in header line of file ' |
|
filename | disp ('Recognized format:') disp('%%MatrixMarket matrix representation field symmetry') error('Check header line.') end if(~ strcmp(head0 |
|
filename MatrixMarket | error ('Not a valid MatrixMarket header.') end if(~ strcmp(head1 |
|
filename MatrixMarket matrix | disp (['This seems to be a MatrixMarket ', head1,' file.']) |
|
| disp ('This function only knows how to read MatrixMarket matrix files.') |
|
| disp (' ') |
|
| error (' ') |
|
while | length (commentline) > 0 &commentline(1) |
|
end Read size then branch according to sparse or dense format | if (strcmp(rep, 'coordinate')) % read matrix given in sparse % coordinate matrix format[sizeinfo |
|
| while (count==0) commentline = fgets(mmfile) |
|
| if (commentline==-1) error('End-of-file reached before size information was found.') end[sizeinfo |
|
| if (count > 0 &count ~=3) error('Invalid size specification line.') end end rows = sizeinfo(1) |
|
| fscanf (mmfile,'%f')] |
|
| if (size(T) ~=3 *entries) message |
|
| disp (message) |
|
| error ('Invalid data.') |
|
end | elseif (strcmp(rep, 'array')) % read matrix given in dense % array(column major) format[sizeinfo |
|
| if (strcmp(symm, 'symmetric')|strcmp(symm, 'hermitian')|strcmp(symm, 'skew-symmetric')) for j =1:cols-1 |
|
| zeros (j, 1) |
|
| A (currenti+1:length(A))] |
|
id | i () |
|
elseif(strcmp(field, 'pattern')) % pattern(makes no sense for dense) disp('Matrix type else Unknown matrix type | disp ('Matrix type:', field) error('Invalid matrix type specification. Check header against MM documentation.') |
|
id | appropriate: (diag(A) diag) |
|
| elseif (strcmp(symm, 'hermitian')) A |
|
| elseif (strcmp(symm, 'skew-symmetric')) A |
|
end | fclose (mmfile) |
|
|
| function [A, rows, cols, entries, rep, field, symm] |
|
| end |
|
| header = fgets(mmfile) |
|
if(header==-1) error( 'Empty file.') end % NOTE see note | above [head1, header] = strtok(header) |
|
| head1 = lower(head1) |
|
| rep = lower(rep) |
|
| field = lower(field) |
|
| symm = lower(symm) |
|
end Read through | comments |
|
end Read through ignoring them | commentline = fgets(mmfile) |
|
end Read size | information |
|
end Read size then branch according to sparse or dense format | count = sscanf(commentline,'%d%d%d') |
|
| cols = sizeinfo(2) |
|
| entries = sizeinfo(3) |
|
if(strcmp(field, 'real')) % real valued entries | T = [T |
|
| A = sparse(T(:,1), T(:,2), T(:,3), rows , cols) |
|
| currenti = j*rows |
|
elseif(strcmp(field, 'complex')) % complx valued entries | tmpi = fscanf(mmfile,'%f',1) |
|
for | j |
|
end end If | symmetric |
|