annotate listeningTest/readTestFile.m @ 15:24be5e9ce25b tip

Update README
author Brecht De Man <brecht.deman@bcu.ac.uk>
date Thu, 20 Sep 2018 12:23:20 +0200
parents 4fd284285159
children
rev   line source
b@0 1 function testDat=readTestFile(testFile)
b@0 2 fid=fopen(testFile,'r');
b@0 3 testDat.sndRef=[];
b@0 4
b@0 5
b@0 6 while ~feof(fid)
b@0 7 lin=fgetl(fid);
b@0 8 [word1,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%s',1);
b@0 9
b@0 10 if (~COUNT | ~strcmp(word1,'%'))
b@0 11
b@0 12 switch upper(word1)
b@0 13
b@0 14 case 'NAME'
b@0 15 testDat.name=fgetl(fid);
b@0 16
b@0 17 case 'COMBINATIONS:'
b@0 18 [nbComb,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin(NEXTINDEX:end),'%d',1);
b@0 19 testDat.nbComb=nbComb; %%
b@0 20 testDat.posComb=[];
b@0 21
b@0 22 for noComb=1:nbComb
b@0 23 lin=fgetl(fid);
b@0 24 if ~isempty(lin)
b@0 25 if lin(1)~='%'
b@0 26 [comb,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%d',2);
b@0 27 testDat.comb(noComb,:)=comb; %%
b@0 28
b@0 29 % Read the reference DATAS
b@0 30 if COUNT==1
b@0 31 lin=lin(NEXTINDEX:end);
b@0 32 [stri,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%s',1);
b@0 33
b@0 34 if findstr(lower(stri),'ref')
b@0 35 testDat.sndRef(end+1)=comb(1);
b@0 36 lin=lin(NEXTINDEX:end);
b@0 37 [stri,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%s',1);
b@0 38 end
b@0 39
b@0 40 if findstr(lower(stri),'pos')
b@0 41 lin=lin(NEXTINDEX:end);
b@0 42 end
b@0 43
b@0 44 % read the sounds default position
b@0 45 [posComb,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%f',inf); % position must be specified for each scale!!
b@0 46 if ~isempty(posComb)
b@0 47 testDat.posComb(noComb,:)=posComb';
b@0 48 end
b@0 49 end
b@0 50 end
b@0 51 end
b@0 52 end
b@0 53 % tricky here! try to satisfy both comp1d and 2d
b@0 54 % requirements of default position of icons
b@0 55 % may be should decompose each case...
b@0 56
b@0 57 posComb=testDat.posComb;
b@0 58 [nbComb1,nbPos]=size(posComb);
b@0 59 if isempty(nbComb1)
b@0 60 nbComb1=1;
b@0 61 end
b@0 62 if exist('nbScale')
b@0 63 nbPos=nbScale;
b@0 64 end
b@0 65 if nbComb1<nbComb
b@0 66 testDat.posComb(nbComb,nbPos)=0;
b@0 67 end
b@0 68 indx=find(testDat.posComb==0);
b@0 69 testDat.posComb(indx)=nan; % mark the combinations with unknown position
b@0 70
b@0 71 case 'NBSCALES:'
b@0 72 [nbScale,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin(NEXTINDEX:end),'%d',1);
b@0 73 testDat.nbScale=nbScale;
b@0 74 % check posRef length
b@0 75 nbRef=length(testDat.sndRef);
b@0 76
b@0 77 for noRef=1:nbRef
b@0 78 if length(testDat.posComb(:,testDat.sndRef(noRef)))~=nbScale
b@0 79 fprintf(1,'Watch out, the position of reference %d are not specified for all scale',noRef);
b@0 80 end
b@0 81 end
b@0 82 for noScale=1:nbScale
b@0 83
b@0 84 while ~feof(fid)
b@0 85 lin=fgetl(fid);
b@0 86 [header,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%s',1);
b@0 87
b@0 88 switch firstWord(header)
b@0 89 case 'SCALE:'
b@0 90 lin=lin(NEXTINDEX:end);
b@0 91 name=lin; %%
b@0 92 case 'min'
b@0 93 lin=lin(NEXTINDEX:end);
b@0 94 [minn,COUNT,ERRMSG,NEXTINDEX]=sscanf(lin,'%d',1); %%
b@0 95 level{1}=lin(NEXTINDEX:end); %%
b@0 96 case 'max'
b@0 97 lin=lin(NEXTINDEX:end);
b@0 98 [maxx,COUNT,ERRMSG,NEXTINDEX]=sscanf(lin,'%d',1); %%
b@0 99 level{3}=lin(NEXTINDEX:end); %%
b@0 100
b@0 101 case 'step'
b@0 102 lin=lin(NEXTINDEX:end);
b@0 103 [stepp,COUNT,ERRMSG,NEXTINDEX]=sscanf(lin,'%d',1); %%
b@0 104 level{2}=lin(NEXTINDEX:end); %%
b@0 105 break
b@0 106 end
b@0 107
b@0 108 end
b@0 109 testDat.scale(noScale).name=name;
b@0 110 testDat.scale(noScale).maxx=maxx;
b@0 111 testDat.scale(noScale).minn=minn;
b@0 112 testDat.scale(noScale).stepp=stepp;
b@0 113 testDat.scale(noScale).level=level;
b@0 114 end
b@0 115 end
b@0 116 end
b@0 117 end
b@0 118 fclose(fid);
b@0 119
b@0 120 function word=firstWord(word)
b@0 121
b@0 122 if ~isempty(word)
b@0 123 if word(1)=='%'
b@0 124 word=[];
b@0 125 end
b@0 126 else
b@0 127 word=[];
b@0 128 end