function DisplaySingleAnalysis(MineralList,data,controlstruct)
%DisplaySingleAnalysis(MineralList,data)
%In cases where the APHID Input data includes only a single analysis the 
%results are printed to the screen.  This program prints out all data 
%about the analysis including: original weights, model weights, perfect weights
%and original and model cations.
%The program also writes this information to LastSingle.csv in the output
%directory
%
%INPUT
%data = The raw data that is output from finder.m
%MineralList =  a structure array (with a length of one in this case) that
%contains the key for access into the data
%controlstruct = the structure the contains the basic information about
%this APHID run, created in APHIDengine
%
%Written by K. Steffen (ksteffen@unm.edu) at the University of New Mexico,
%Department of Earch and Planetary Science
%Copyright 2003 Kurt Steffen
%
%Last Modified June 20, 2003

dispdouble = zeros(7,length(data{1}{MineralList.WeightOriginalLocation})+1);
dispdouble(1,1:end-1) = data{1}{MineralList.WeightOriginalLocation}; %original weight
dispdouble(1,end) = sum(dispdouble(1,:));		
dispdouble(2,1:end-1) = data{1}{MineralList.WeightLocation}; %model weight
dispdouble(2,end) = sum(dispdouble(2,1:end-1));
dispdouble(3,1:end-1) = data{1}{MineralList.WeightPerfectLocation}; %perfect weight
dispdouble(3,end) = sum(dispdouble(3,1:end-1));
relative = dispdouble(2,:)-dispdouble(1,:);
dispdouble(4,:) = relative;  %model error
dispdouble(4,end) = sum(abs(relative(1:end-1)));
relative = dispdouble(3,:)-dispdouble(1,:);
dispdouble(5,:) = relative; %perfect error
dispdouble(5,end) = sum(abs(relative(1:end-1)));

numbercations = length(MineralList.CationOrder);
dispdouble(6,1:end-1) = data{1}{MineralList.CationOriginalLocation}(1:numbercations);  %original cations
dispdouble(7,1:end-1) = data{1}{MineralList.CationLocation}; %model cations
dispdouble(6,end) = sum(dispdouble(6,1:end-1));
dispdouble(7,end) = sum(dispdouble(7,1:end-1));

%calculating a total with the H (an unanalyzed component) removed from consideration
%errors (for the identification process) are also alway calculated with H removed
%from the analysis
Hcol = GetColumnsGeneral3(MineralList.WeightPerfectOrder,{'H'}); 
if Hcol{2,1} ~= -1
	Hcol = Hcol{2,1};
	Hdisp = dispdouble(:,Hcol);
	dispdouble(:,end+1) = abs(dispdouble(:,end)-Hdisp);
	dispcell = double2cell(dispdouble);
	dispcell = [MineralList.WeightPerfectOrder {'Total'} {'Total - H'} ;dispcell];
else	
	dispcell = double2cell(dispdouble);
	dispcell = [MineralList.WeightPerfectOrder {'Total'} ;dispcell];
end

labels = [{''};{'Original Weight'};{'Model Weight'};{'Perfect Weight'};...
{'Error Model'};{'Error Perfect'};{'Original Cations'};{'Model Cations'}];
dispcell = [dispcell labels];
disp(dispcell)

filename = [pwd filesep 'Output' filesep 'LastSingle.csv'];
writecsv(filename,dispcell,'a');
disp(sprintf('Real-time results saved at %s',filename));