%generate html table with randomized tones


phonlist=str2mat('S','SH','X','Z','ZH','J','C','CH','Q','R');
myprefix='mf';
myvp='1';
%myvp='_21';
mysuffix='_1';
myfile=['mandarin_uebung' myvp mysuffix];

ntone=4;

nphon=size(phonlist,1);

diary([myfile '.html']);

ss=['<table BORDER COLS=' int2str(nphon+1) 'WIDTH="100%" >'];
disp(ss);

solbuf=cell(nphon,ntone);

stimlist=zeros(nphon*ntone,2);

ipi=1;
for ii=1:nphon
    for jj=1:ntone
        stimlist(ipi,:)=[ii jj];
        ipi=ipi+1;
    end;
end;

ranlist=randperm(nphon*ntone);

ipi=1;
    for iphon=1:nphon
    disp('<tr>');
    ss=['<td>' int2str(iphon) '</td>'];
    disp(ss);

%    tonelist=1:ntone;
    for itone=1:ntone

        iran=ranlist(ipi);

        phoni=stimlist(iran,1);
        tonei=stimlist(iran,2);
        
        mysound=deblank(phonlist(phoni,:));
        mytone=int2str(tonei);

        solbuf{iphon,itone}=[mysound mytone];    
        ipi=ipi+1;

        mywav=[myprefix mysound mytone myvp '.wav'];
        mystimf=['stim_' myprefix myvp mysuffix '_' int2str(iphon) int2str(itone) '.wav'];
        copyfile(mywav,mystimf);
        
        mytext='';
        mysolution='';
        ss=['<td><a href="' mystimf '">.  ' mytext '  .</a></td>'];
        disp(ss);
    end;
    disp('</tr>');
end;

disp('</table>');

diary off

diary([myfile '_sol.txt']);
disp(solbuf);
diary off;

    %<td><a href="ls_ewe_tone1_35_01_nglo.wav">nglO</a></td>
        