function exportOneSVM( weights, ni, mu, SVMFile, datestamp, certVersion, prefix, precision )
% weights is a 9216xn array, with n being the number of AUs. This is one slice of the full SVMWeights data
% ni and mu are frequencies
% SVMFile is the name of the matlab file that is the source of these weights
% date is a string containing a date/time stamp when export started
% certVersion is a string describing the SVN version (can be used to reproduce these weights)
% prefix is a string that will be used to name the exported files
% precision is the number of digits after the decimal place to output


    % if no precision given, default to 8
    % if no prefix given, default to "SVMWeights"
    if( nargin() < 8 )
        precision = 8;
    end
    if( nargin() < 7 )
        prefix = 'SVMWeights';
    end

    precFormat = sprintf( '%%.%df ', precision );

% I could use ischar to make sure prefix is a character type, but I think it's better to insist that prefix and 
% precision be in a particular order.

    fname = sprintf( '%s_%d_%d.xml', prefix, ni, mu );
    fid = fopen( fname, 'w' );
    if( fid == -1 )
        disp( 'Unable to open file for writing SVM weights.' );
        return;
    end

    rowmax = size(weights,1);
    colmax = size(weights,2);
    if( (colmax == 9216) || (rowmax ~= 9216) )
        disp( 'Error with weights shape.' );
        return;
    end

    % write the header
    fprintf( fid, '<?xml version="1.0" encoding="UTF-8"?>\n' );
    fprintf( fid, '<svm category="%s" ni="%d" mu="%d" colcount="%d" rowcount="9216" file="%s" date="%s" cert="%s" >\n', prefix, ni, mu, colmax, SVMFile, datestamp, certVersion );

    for i = 1:rowmax
        fprintf( fid, '<row>' );
        
        for j = 1:colmax
            fprintf( fid, precFormat, weights(i,j) );
        end

        fprintf( fid, '</row>\n' );
    end

    fprintf( fid, '</svm>\n' );
    fclose( fid );
