%function AUcodes = convert_EH(r)
%
%Reads and interprets codes from Ekman-Hager filenames.
%Reads in a struct of filenames r created by r=dir
%Returns AUcodes, a cell array containing:
%Filename subject_no  intensity  AU_list

function AUcodes = convert_EH(r)


for i=3:size(r,1)
     fname=r(i).name;
     subj = str2num(fname(1:2));
     intens = str2num(fname(4));
     code=fname(10:12);

%LOOK UP TABLE 
switch (code)
case ('001');   AUlist={1};
case ('002');   AUlist={     2};
case ('004');   AUlist={     4};
case ('005');   AUlist={     5};
case ('006');   AUlist={     6};
case ('007');   AUlist={     7};
case ('009');   AUlist={     9};
case ('010');   AUlist={     10};
case ('011');   AUlist={     11};
case ('012');   AUlist={     12};
case ('013');   AUlist={     13};
case ('014');   AUlist={     14};
case ('015');   AUlist={     15};
case ('016');   AUlist={     16};
case ('017');   AUlist={     17};
case ('018');   AUlist={     18};
case ('020');   AUlist={     20};
case ('022');   AUlist={     22};
case ('023');   AUlist={     23};
case ('024');   AUlist={     24};
case ('038');   AUlist={     38};
case ('039');   AUlist={     39};
case ('000');   AUlist={     1, 2};
case ('003');   AUlist={     1, 2, 4};
case ('00a');   AUlist={     1, 2, 4, 5};
case ('00b');   AUlist={     1, 2, 4, 5, 6};
case ('00c');   AUlist={     1, 2, 4, 5, 6, 7};
case ('00d');   AUlist={     1, 4};
case ('00e');   AUlist={     1, 4, 5};
case ('00f');   AUlist={     1, 4, 5, 6};
case ('01a');   AUlist={     1, 4, 5, 6, 7};
case ('02a');   AUlist={     1, 5};
case ('02b');   AUlist={     1, 5, 6};
case ('02c');   AUlist={     1, 5, 6, 7};
case ('02d');   AUlist={     1, 6};
case ('02e');   AUlist={     1, 6, 7};
case ('02f');   AUlist={     1, 7};
case ('03a');   AUlist={     1, 2, 5};
case ('03b');   AUlist={     1, 2, 5, 6};
case ('03c');   AUlist={     1, 2, 5, 6, 7};
case ('03d');   AUlist={     1, 2, 6};
case ('03e');   AUlist={     1, 2, 6, 7};
case ('03f');   AUlist={     1, 2, 7};
case ('04a');   AUlist={     1, 2, 4, 6};
case ('04b');   AUlist={     1, 2, 4, 6, 7};
case ('04c');   AUlist={     1, 2, 5, 7};
case ('04d');   AUlist={     1, 5, 7};
case ('04e');   AUlist={     1, 2, 4, 7};
case ('04f');   AUlist={     1, 2, 4, 5, 7};
case ('050');   AUlist={     1, 4, 6};
case ('051');   AUlist={     1, 4, 6, 7};
case ('052');   AUlist={     1, 4, 7};
case ('053');   AUlist={     1, 4, 5, 7};
case ('054');   AUlist={     2, 4};
case ('055');   AUlist={     2, 4, 5};
case ('056');   AUlist={     2, 4, 5, 6};
case ('057');   AUlist={     2, 4, 5, 6, 7};
case ('058');   AUlist={     2, 4, 6};
case ('059');   AUlist={     2, 4, 6, 7};
case ('05a');   AUlist={     2, 4, 7};
case ('05b');   AUlist={     2, 5};
case ('05c');   AUlist={     2, 5, 6};
case ('05d');   AUlist={     2, 5, 6, 7};
case ('05e');   AUlist={     2, 5, 7};
case ('05f');   AUlist={     2, 6};
case ('060');   AUlist={     2, 6, 7};
case ('061');   AUlist={     2, 7};
case ('062');   AUlist={     4, 5};
case ('063');   AUlist={     4, 5, 6};
case ('064');   AUlist={     4, 5, 6, 7};
case ('065');   AUlist={     4, 5, 7};
case ('066');   AUlist={     4, 6};
case ('067');   AUlist={     4, 6, 7};
case ('068');   AUlist={     4, 7};
case ('069');   AUlist={     5, 6};
case ('06a');   AUlist={     5, 6, 7};
case ('06b');   AUlist={     5, 7};
case ('06c');   AUlist={     6, 7};
case ('06d');   AUlist={     2, 4, 5, 7};
case ('06f');   AUlist={     9, 25};
case ('070');   AUlist={     10, 25};
case ('071');   AUlist={     16, 25};
case ('072');   AUlist={     12, 25};
case ('073');   AUlist={     6, 12};
case ('074');   AUlist={     6, 12, 25};
case ('075');   AUlist={     7, 12};
case ('076');   AUlist={     7, 12, 25};
case ('077');   AUlist={     6, 7, 12};
case ('078');   AUlist={     6, 7, 12, 25};
case ('079');   AUlist={     22, 25};
case ('07a');   AUlist={     9, 16, 25};
case ('07b');   AUlist={     10, 16, 25};
case ('07c');   AUlist={     9, 17};
case ('07d');   AUlist={     10, 15};
case ('07e');   AUlist={     10, 17};
case ('07f');   AUlist={     15, 17};
case ('080');   AUlist={     10, 15, 17};
case ('081');   AUlist={     20, 25};
case ('082');   AUlist={     20, 26};
case ('083');   AUlist={     20, 27};
case ('084');   AUlist={     10, 14};
case ('085');   AUlist={     14, 17};
case ('086');   AUlist={     10, 20, 25};
case ('087');   AUlist={     10, 12, 25};
case ('088');   AUlist={     12, 16, 25};
case ('089');   AUlist={     10, 12, 16, 25};
case ('08a');   AUlist={     12, 15};
case ('08b');   AUlist={     12, 15, 17};
case ('08c');   AUlist={     6, 12, 15};
case ('08d');   AUlist={     6, 12, 15, 17};
case ('08e');   AUlist={     12, 26};
case ('08f');   AUlist={     12, 27};
case ('090');   AUlist={     12, 17};
case ('091');   AUlist={     10, 23, 25};
case ('092');   AUlist={     12, 23};
case ('093');   AUlist={     12, 24};
case ('094');   AUlist={     14, 23};
case ('095');   AUlist={     17, 23};
case ('096');   AUlist={     17, 24};
case ('097');   AUlist={     6, 12, 17, 23};
case ('098');   AUlist={     12, 17, 23};
case ('099');   AUlist={     10, 17, 23};
case ('09a');   AUlist={     18, 23};
case ('09b');   AUlist={     15, 23};
case ('09c');   AUlist={     23, 26};
case ('09d');   AUlist={     22, 23, 25};
case ('09e');   AUlist={     20, 23, 25};
case ('09f');   AUlist={     6, 12, 26};
case ('0a0');   AUlist={     6, 7, 12, 26};
case ('0a1');   AUlist={     7, 12, 26};
case ('0a2');   AUlist={     10, 15, 25};
case ('0a3');   AUlist={     10, 14, 25};
case ('0a4');   AUlist={     14};
case ('0a5');   AUlist={     10, 14};
case ('0a6');   AUlist={     10, 14, 25};
case ('0a7');   AUlist={     1, 2, 12, 25};
case ('0a8');   AUlist={     1, 2, 12, 26};
case ('0a9');   AUlist={     1, 2, 6, 7, 12};
case ('0aa');   AUlist={     1, 2, 6, 7, 12, 25};
case ('0ab');   AUlist={     1, 2, 6, 7, 12, 26};
case ('0ac');   AUlist={     1, 2, 4, 20};
case ('0ad');   AUlist={     1, 2, 4, 20, 25};
case ('0ae');   AUlist={     1, 2, 4, 5, 7, 20};
case ('0af');   AUlist={     1, 2, 4, 5, 7, 20, 25};
case ('0b0');   AUlist={     4, 23};
case ('0b1');   AUlist={     4, 24};
case ('0b2');   AUlist={     4, 7, 23};
case ('0b3');   AUlist={     4, 7, 24};
case ('0b4');   AUlist={     4, 5, 23};
case ('0b5');   AUlist={     1, 2, 4, 5, 20};
case ('0b6');   AUlist={     4, 5, 24};
case ('0b7');   AUlist={     4, 5, 7, 23};
case ('0b8');   AUlist={     4, 5, 7, 24};
case ('0b9');   AUlist={     4, 5, 7, 23, 25};
case ('0ba');   AUlist={     1, 2, 15, 17};
case ('0bb');   AUlist={     1, 17};
case ('0bc');   AUlist={     1, 15};
case ('0bd');   AUlist={     1, 4, 15};
case ('0be');   AUlist={     1, 4, 17};
case ('0bf');   AUlist={     1, 4, 15, 17};
case ('0c1');   AUlist={     1, 2, 20};
case ('0c2');   AUlist={     1, 2, 4, 5, 20, 25};
case ('0c3');   AUlist={     1, 2, 4, 5, 20};
case ('0c4');   AUlist={     1, 2, 4, 5, 7, 20};
case ('0c5');   AUlist={     4, 9};
case ('0c6');   AUlist={     4, 7, 9};
case ('0c7');   AUlist={     4, 6, 7, 9};
case ('0c8');   AUlist={     4, 14};
case ('0c9');   AUlist={     4, 7, 14};
case ('0ca');   AUlist={     1, 4, 6, 7, 15};
case ('0cb');   AUlist={     1, 4, 6, 7, 15, 17};
case ('0cd');   AUlist={     1, 2, 26};
case ('0ce');   AUlist={     1, 2, 27};
case ('0d1');   AUlist={     14, 25};
case ('0d2');   AUlist={     14, 26};
case ('0d3');   AUlist={     9, 26};
case ('0d4');   AUlist={     10, 26};
case ('0d5');   AUlist={     10, 14, 25};
end

     AUcodes{i-2,1} = fname;
     AUcodes{i-2,2} = subj;
     AUcodes{i-2,3} = intens;
     AUcodes{i-2,4} = AUlist;

end
