function ErrorTable=maketable(TabFID,MethodGroup,p1,p2)
% MAKETABLE  Make table of classification errors
%	ErrorTable=maketable(fid,MethodGroup,p1,p2)
%	p1 and p2 are optional. If the default values are to be used,
%	they must be left unspecified or empty.
%	
%	Legal values for MethodGroup:
%	- 1  Non-wavelet heuristic filterbanks
%	- 2  Wavelet transform/frames and QMF critically sampled 
%	     filterbanks
%	- 3  Wavelet frame (non-subsampled), p1=Filt. len., p2=Struct.
%	- 4  Optimal filters and filterbanks
%	- 5  Classical nonfiltering approaches
%	- 6  Gabor filter with various nonlinearities
%	
%	Example:
%	fid=fopen('maketable.tab','w'); 
%	for k=1:6, maketable(fid,k); end
%	fclose(fid);
%	!/home/signal/tranden/bin/print -fCourier10 maketable.tab

if exist('p1')~=1, p1=[]; end
if exist('p2')~=1, p2=[]; end
TestEdgeCut=20;

ErrorTable=[];

FeatureIds=[];
if     MethodGroup==1, % 		Non-wavelet heuristic filterbanks
  FeatureIds=strlst(FeatureIds,'Laws-Sqr-Gauss-Log-LVQ');
  FeatureIds=strlst(FeatureIds,'Isotropic-Sqr-Gauss-Log-LVQ');
  FeatureIds=strlst(FeatureIds,'Gabor-Sqr-Gauss-Log-LVQ');
  FeatureIds=strlst(FeatureIds,'DCT-Sqr-Gauss-Log-LVQ');
  for Basis=['f16b      ';'i_2_1_smpl';'i_2_1_09  ';'Gabor     ']'
    Basis=deblank(Basis');
    for Struct=[7 14 6 15 8]
      FeatureIds=strlst(FeatureIds,...
	sprintf('QMF:%s:%02d:Full-Sqr-Gauss-Log-LVQ',Basis,Struct));
    end
  end
  for Struct=[14 6 15 8]
    FeatureIds=strlst(FeatureIds,sprintf('Gabor:%02d-Sqr-Gauss-Log-LVQ',...
      Struct));
  end
elseif MethodGroup==2, % 		Wavelet transform and frames
  for Struct=[14 6 15 8]
    for FilterLength=[4 6 8 10 12 20]
      FeatureIds=strlst(FeatureIds,...
	sprintf('QMF:w_dau%d:%d:Dec-Sqr-Gauss-Log-LVQ',FilterLength,Struct));
    end
    for Basis=['f16b      ';'i_2_1_smpl';'i_2_1_09  ']'
      Basis=deblank(Basis');
      FeatureIds=strlst(FeatureIds,...
	sprintf('QMF:%s:%02d:Dec-Sqr-Gauss-Log-LVQ',Basis,Struct));
    end
  end
elseif MethodGroup==3, % 		Wavelet frame (non-subsampled)
  if isempty(p1), FilterLengths=[4 6 8 10 12 20]; else FilterLengths=p1; end
  if isempty(p1), Structs=[14 6 15 8];            else Structs=p1;       end
  for Struct=Structs
    for FilterLength=FilterLengths
      FeatureIds=strlst(FeatureIds,...
	sprintf('QMF:w_dau%d:%d:Full-Sqr-Gauss-Log-LVQ',FilterLength,Struct));
    end
  end
elseif MethodGroup==4, % 		Optimal filters
  for sigma=[2 4 8 16]
    FeatureIds=strlst(FeatureIds,...
      sprintf('Dunn:%d-Sqr-Gauss-Log-Thresh',sigma));
  end
  FeatureIds=strlst(FeatureIds,'Singh-Sqr-Gauss-Log-Thresh');
  FeatureIds=strlst(FeatureIds,'Unser-Sqr-Gauss-Log-Thresh');
  FeatureIds=strlst(FeatureIds,'Unser-Sqr-Gauss-Log-LVQ');
  FeatureIds=strlst(FeatureIds,'Unser:7:3-Sqr-Gauss-Log-LVQ');
  FeatureIds=strlst(FeatureIds,'Unser:7:4-Sqr-Gauss-Log-LVQ');
  FeatureIds=strlst(FeatureIds,'Unser:7:6-Sqr-Gauss-Log-LVQ');
  FeatureIds=strlst(FeatureIds,'Unser:7:3-Sqr-Gauss-Log-Thresh');
  FeatureIds=strlst(FeatureIds,'Unser:7:4-Sqr-Gauss-Log-Thresh');
  for M_h=[5 7 11 13 15 17]
    for sigma_w=[6 8 9]
      FeatureIds=strlst(FeatureIds,...
	sprintf('Unser:%d:%d-Sqr-Gauss-Log-Thresh',M_h,sigma_w));
    end
  end
  FeatureIds=strlst(FeatureIds,'Fisher-Sqr-Gauss-Log-Thresh');
  FeatureIds=strlst(FeatureIds,'Eigen-Sqr-Gauss-Log-LVQ');
  FeatureIds=strlst(FeatureIds,'Bovik-Sqr-Gauss-Log-LVQ');
  FeatureIds=strlst(FeatureIds,'LinPred-Sqr-Gauss-Log-Min');
  FeatureIds=strlst(FeatureIds,'LinPred-Sqr-Gauss-Log-LVQ');
  for ClassifId=['LVQ   ';'Thresh']'
    ClassifId=deblank(ClassifId');
    for NumFilt=[4 6 10]
      FeatureIds=strlst(FeatureIds,...
	sprintf('Weldon:%d-Sqr-Gauss-Log-%s',NumFilt,ClassifId));
    end
  end
  FeatureIds=strlst(FeatureIds,'NNFilt:11--Median--');
  FeatureIds=strlst(FeatureIds,'NNFilt:21--Median--');
elseif MethodGroup==5, % 		Classical approaches
  FeatureIds=strlst(FeatureIds,'cooc----LVQ');
  FeatureIds=strlst(FeatureIds,'cooc:32----LVQ');
  FeatureIds=strlst(FeatureIds,'SAR--Gauss--LVQ');
elseif MethodGroup==6, % 		Gabor-tanh:0.1-Gauss--LVQ
  FeatureIds=strlst(FeatureIds,'Gabor-Sqr-Gauss-Log-LVQ');
  FeatureIds=strlst(FeatureIds,'Gabor-Sqr-Gauss--LVQ');
  FeatureIds=strlst(FeatureIds,'Gabor-Sqr-Gauss-Sqrt-LVQ');
  FeatureIds=strlst(FeatureIds,'Gabor-Abs-Gauss-Sqrt-LVQ');
  FeatureIds=strlst(FeatureIds,'Gabor-Abs-Gauss-Log-LVQ');
  FeatureIds=strlst(FeatureIds,'Gabor-Abs-Gauss--LVQ');
  for alpha=[0.001:0.001:0.01 0.015 0.02:0.01:0.07 0.075 ...
	0.08 0.09 0.099 0.1 0.12 0.15 0.17 0.2 0.25 0.3 0.5]
    FeatureIds=strlst(FeatureIds,...
      ['Gabor-tanh:' num2str(alpha) '-Gauss--LVQ']);
  end
end

ImageIds=[...
  'Nat-5c    '; ...
  'Nat-10    '; ...
  'Nat-16c   '; ...
  'GMRF      '; ...
  'D1001D1002'; ...
  'D0004D0084'; ...
  'D0012D0017'; ...
  'D0005D0092'];

for FeatureNo=1:size(FeatureIds,1)
  FeatureId=deblank(FeatureIds(FeatureNo,:));
  fprintf(TabFID,FeatureIds(FeatureNo,:));
  for ImageNo=1:size(ImageIds,1)
    ImageId=deblank(ImageIds(ImageNo,:));
    ExpId=[ImageId '-' FeatureId];
    ErrorFN=['results/' ExpId '-Error.txt'];
    ClassMapFN=['results/' ExpId '.gif'];
    if exist(ErrorFN)==2
      % Read error text file
      fid=fopen(ErrorFN,'r'); 
      ErrorTable(FeatureNo,ImageNo)=fscanf(fid,'%f');
      fclose(fid);
    else
      ErrorTable(FeatureNo,ImageNo)=NaN;
    end
  end
  fprintf(TabFID,' %4.1f',ErrorTable(FeatureNo,:)); fprintf(TabFID,'\n');
end
fprintf(TabFID,'\n');
  

