function writeCDs(CDs, fileName)
% write a text file with sufficient information to be
% able to retrieve a structure file from it

fh = fopen(fileName, 'w');
attribs = fieldnames(CDs);                  % Note 1
fprintf(fh,'%d\t%d\n', length(CDs), length(attribs) );
for index = 1:length(attribs)               % Note 2
    fprintf(fh, '%s\t', attribs{index} );
end
fprintf(fh,'\n');                           % Note 3
for index = 1:length(attribs)
    att = attribs{index};
    type{index} = class(CDs(1).(att));      % Note 4
    fprintf(fh, '%s\t', type{index} );
end
fprintf(fh,'\n');
for CD = CDs                                % Note 5
    for index = 1:length(attribs)
        switch class(CD.(attribs{index}))
            case 'char'
                str = ['"' CD.(attribs{index}) '"'];
            case 'double'
                str = sprintf('%g', CD.(attribs{index}) );
        end
        fprintf(fh, '%s\t', str );          % Note 6      
    end
    fprintf(fh,'\n');                       % Note 7
end

fclose(fh);


