(* Getting list of excluded pictures *) maintainExclude := ( exclusions[_] := {}; SetDirectory[dirwork]; filelist = "exclude.txt"; data = Import[filelist, "Lines"]; data = Select[data, ! StringMatchQ[#, "'*'"] &]; data1 = Select[data, ! StringFreeQ[#, "'"] &]; If[data1 =!= {}, Print["Warning: ", filelist, ": some lines contain ' character: ", data1]]; data = Split[ data, ! StringMatchQ[#1, Whitespace ...] && ! StringMatchQ[#2, Whitespace ...] &]; data = Select[data, ! StringMatchQ[#[[1]], Whitespace ...] &]; md = Length[data]; Print["Excluding some pictures for ", md, " plants ..."]; namese = #[[1]] & /@ data; dups = Tally[namese]; dups = Select[dups, #[[2]] =!= 1&]; If[dups =!= {}, Print["Warning: There are duplicate names in exclusion list: ", dups // TableForm]]; names1e = Complement[namese, plantlista]; m1 = Length[names1e]; If[m1 >0, Print["Warning: There are ", m1, " plants in exclusion list that are not in the plant list: ", Short[names1e, 50]]]; Do[ name = First[dat]; If[Length[dat] == 1, Print["Error: exclude.txt: Length of the record should be larger than 1: ", name]]; excls = Drop[dat, 1]; excls = StringSplit[excls, {" ", "-"}]; If[excls[[1]] =!= {}, Do[ If[Length[excl] =!= 2, Print["Error: exclude.txt: Length not equal to 2: ", name, " -> ", excl]]; {r, p} = excl; If[!StringMatchQ[r, RegularExpression["\\d{1,5}"]] || !StringMatchQ[p, RegularExpression["\\d{1,3}"]], Print["Error: exclude.txt: roll or pic are not numbers: ", name, " -> ", excl]], {excl, excls}]; exclusions[name] = excls], {dat, data}]; (* Re-writing exclusion list in alphabetic order *) filelist1 = "exclude1.txt"; mexcls = 0; lines = Table[ excls = exclusions[plant]; excls = Sort[excls, (100 ToExpression[#1[[1]]] + ToExpression[#1[[2]]] < 100 ToExpression[#2[[1]]] + ToExpression[#2[[2]]]) &]; dups = Tally[excls]; dups = Select[dups, #[[2]] =!= 1&]; If[dups =!= {}, Print["Warning: there are duplicate exclusions for the plant ", plant, ": ", dups]]; {plant, If[excls === {}, "-", mexcls = mexcls + Length[excls]; Table[excl[[1]] <> "-" <> excl[[2]],{excl, excls}]], ""}, {plant, plantlist(*a*)}]; Export[filelist1, Flatten[lines], "Lines"]; Print[mexcls, " exclusions were written into file ", filelist1]; );