function save_bases_as_kernels( A, dim_r, prefix, filterfile, flevel, fbins)
% save_bases_as_kernels - save bases as filters
%
% A        the bases, with patches as column vectors
% prefix - the prefix of those kernels
%
fp = fopen(filterfile,'wb');
fprintf(fp,'%d\n', size(A,2));
% This is the side of the window
dim_c = size(A,1)/dim_r;
if dim_c - floor(dim_c)~=0 error('Filter size not interger!'); end;
for i=1:size(A,2),
    fname = [sprintf('%s_%d.ker', prefix,i-1)];
    % This sets the patch
    I = reshape(A(:,i),[dim_r dim_c]);
    writeakernel_dat(I, fname);
    fprintf(fp,'%d\n%s\n%d\n\n',flevel, fname, fbins);
    disp(sprintf('Saving %dth basis to file %s ... Done.', i, fname));
end
fclose(fp);
return;


