function [] = outputSparseMatrix(A,m,n,fn, numItems, scale)
% outputSparseMatrix.m
% outputSparseMatrix(A)
% create correct output to check test input for students

if any(size(A) ~= [m n])
  error('outputSparseMatrix: A has bad dimensions');
end

fid = fopen(fn,'w');

fprintf(fid,'# outputSparseMatrix.m \n');
fprintf(fid,'m = %d   n = %d   numItems = %d', m, n, numItems);
if exist('scale')
  fprintf(fid,'   const = %d', scale);
end
fprintf(fid,'\n');

% This makes a list of all the values in A and their coordinates
% and puts it in 3 parallel arrays.
[Am,An,val] = find(A);


format long;
% Iterate over the parallel arrays and output values.
for Ai=1:length(val)
  fprintf(fid,'%d,%d = %d \n',Am(Ai)-1,An(Ai)-1,val(Ai));
end

fclose(fid);