function spewsdif(filename, whichframes, stypesfile)
% Print the contents of an SDIF file to the screen, like the 
% C program "spew-sdif.c".
%
% By Matt Wright (CCRMA/CNMAT), March 2004
%
% filename: name of SDIF file
% whichframes: optional array of frames to be printed.  (Omit = print all)
% stypesfile: optional path to IRCAM's required SdifTypes.STYP
%     (Omit = use Matt's)

if (nargin < 2)
    whichframes = 0;
end

if (nargin < 3)
    stypesfile = '/user/m/matt/matlab/sdif/SdifTypes.STYP';
end

sdifexist(filename);

[ data, header, frame, matrix ] = loadsdiffile(filename, stypesfile);

nframes = size(data,2);

if nframes ~= size(header,1)
   error(['Data has ' num2str(nframes) ' frames but header has only ' ...
          num2str(size(header,1))])
end


if nframes ~= size(frame,1)
   error(['Data has ' num2str(nframes) ' frames but frame type array has only ' ...
          num2str(size(frame,1))])
end

if nframes ~= size(matrix,1)
   error(['Data has ' num2str(nframes) ' frames but matrix type array has only ' ...
          num2str(size(matrix,1))])
end


if whichframes == 0
   whichframes = 1:nframes;
end


allstreams = [];

for i = whichframes
    streamID = header(i,2);
    disp(['Frame ' num2str(i) ': Type ' char(frame(i,:)) ', time ' ...
          num2str(header(i,1)) ', StreamID ' num2str(streamID) ]);

    if (find(allstreams == streamID))
       % Already saw this stream
    else
	disp(['   --- First frame with stream ID ' num2str(streamID)]);
        allstreams = [allstreams streamID];
    end

    m = data{i};
    [rows, cols] = size(m);

    disp(['  Matrix: type ' char(matrix(i,:)) ', ' num2str(rows) ' Rows, ' ...
          num2str(cols) ' Columns']);

    disp(m);
end

disp([num2str(length(allstreams)) ' unique StreamIDs found in the file:']);
disp(allstreams);

