function MunsellAnalysisOfColourSet(MunsellList, NameForOutput, NameList);
% Purpose		Given a set of Munsell colours (for example, all the Munsell specifications of a
%				brand of pastels), produce plots of their distributions of Munsell hue, value,
%				and chroma.  Identify other characteristics, like duplicates, that might be
%				of interest to artists and designers.
%
% Description	This routine describes a set of colours in terms of the Munsell system.  It
%				was originally intended to describe a set of pastels.  Pastel sets are large,
%				typically containing hundreds of different colours.  An artist or designer
%				(or pastel manufacturer) needs some way to organize the set, or to see as a
%				whole.  The Munsell system is a natural tool, because it uses perceptual
%				quantities that are of interest visually.  
%
% 				The Munsell system specifies a local colour by giving its hue (H), value (V),
%				and chroma(C) in the form H V/C.  The value is a number between 0 and 10.  
%				The chroma is a positive number, whose bound depends on hue and value,
%				as given by the MacAdam limits.  The hue specification consists of a letter
%				designator (B, BG, G, GY, Y, YR, R, RP, P, PB), and a number designator 
%				which is greater than 0, and less than or equal to 10.  If chroma is
%				0, then the local colour has no hue, and is specified as NV, where N is the
%				string "N," and V is the value.  For example, 5.0R 9.0/4.0 is a light pastel
%				red, while N3 is a dark grey.
%
%				The Munsell specification for each pastel in a set can be calculated from
%				the pastel s reflectance spectrum, which can be measured with a
%				spectrophotometer.  This routine assumes that the Munsell specifications
%				have already been found, and are being input in the variable MunsellList.
%				If desired, a list of names, or manufacturer s designations can also be
%				input in the variable NameList (this argument is optional).  
%
%				The routine produces histograms showing the relative distribution of hues,
%				values, and chromas in the input list.  Munsell leaves are produced
%				(spanning multiple hues) that show colour locations visually.  The input
%				list is checked to identify any pairs that are duplicates or near
%				duplicates.  
%
% Inputs		MunsellList		A list (using {}) of Munsell strings, e.g. 6.2PB 7.0/2.3.
%
%				NameForOutput	A string that will identify which colour set is being
%								analyzed.  This string will be attached to the front of
%								the names of saved figures.
%
%				NameList	An optional argument giving names (or manufacturer numbers) for
%							the Munsell inputs.  The names are treated as strings, even 
%							though they may be numbers.
%
% Author		Paul Centore (February 5, 2014)
% Revised		Paul Centore (January 5, 2015)
%				---Changed -deps to -depsc to preserve colours in saved figures
% Revised		Paul Centore (March 28, 2015)
%				---Saved some variables in text files for easier reference
% Revised		Paul Centore (December 12, 2015)
%				---Made value file printable when no NameList is input
%				---Made checking for duplicates an option, rather than just doing it
%
% Copyright 2014-2015 Paul Centore
%
%    This file is part of MunsellAndKubelkaMunkToolbox.
%
%    MunsellAndKubelkaMunkToolbox is free software: you can redistribute it and/or modify
%    it under the terms of the GNU General Public License as published by
%    the Free Software Foundation, either version 3 of the License, or
%    (at your option) any later version.
%
%    MunsellAndKubelkaMunkToolbox is distributed in the hope that it will be useful,
%    but WITHOUT ANY WARRANTY; without even the implied warranty of
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%    GNU General Public License for more details.
%
%    You should have received a copy of the GNU General Public License
%    along with MunsellAndKubelkaMunkToolbox.  If not, see <http://www.gnu.org/licenses/>.

% Use the following flags to set which plots to display, and whether to look for duplicates
DisplayHueHistogram   = true	;
DisplayValueHistogram = true	;
DisplayChromaHistogram = true	;
DisplayMunsellHueLeaves = false	;
CheckForNearDuplicates = false	;

NumOfColours = length(MunsellList)	;
ASTMHuesInList       = -99 * ones(1,NumOfColours) 	;
MunsellValuesInList  = -99 * ones(1,NumOfColours) 	;
MunsellChromasInList = -99 * ones(1,NumOfColours) 	;
GreysInList          = false * ones(1,NumOfColours)	;
for ctr = 1:NumOfColours
    MunsellSpecString = MunsellList{ctr}									;
    ColorLabMunsellVector = MunsellSpecToColorLabFormat(MunsellSpecString)	;
    if length(ColorLabMunsellVector) == 1 	% Colour is a neutral grey
        MunsellValuesInList(ctr)  = ColorLabMunsellVector(1) 	;
        MunsellChromasInList(ctr) = 0							;
        GreysInList(ctr)          = true 						;
    else									% Colour is not a neutral grey
        MunsellValuesInList(ctr)  = ColorLabMunsellVector(2) 		;
        MunsellChromasInList(ctr) = ColorLabMunsellVector(3)		;
        HueString = HueStringFromMunsellSpec(MunsellSpecString, 2)	;
        ASTMHuesInList(ctr) = MunsellHueToASTMHue(ColorLabMunsellVector(1),...
                                                  ColorLabMunsellVector(4));
    end
end

if DisplayHueHistogram
	% Make a histogram, showing how many colours in the set are in different hue bands
	HueBinWidth = 5									;
	EdgeVector = [0:HueBinWidth:100]				;
	HueCounts = histc(ASTMHuesInList, EdgeVector)	;
	figure
	stairs(EdgeVector, HueCounts, 'k')				;
	RGB5R5Slash6 = [0.735846, 0.309445, 0.433004]	;
	RGB5YR5Slash6 = [0.748867, 0.373079, 0.259971]	;
	RGB5Y5Slash6 = [0.670275, 0.498464, 0.129911]	;
	RGB5GY5Slash6 = [0.542044, 0.628416, 0.156007]	;
	RGB5G5Slash6 = [0.363618, 0.709012, 0.337149]	;
	RGB5BG5Slash6 = [0.306970, 0.699397, 0.467127]	;
	RGB5B5Slash6 = [0.292836, 0.635656, 0.626873]	;
	RGB5PB5Slash6 = [0.381579, 0.486842, 0.710526]	;
	RGB5P5Slash6 = [0.545071, 0.377655, 0.707503]	;
	RGB5RP5Slash6 = [0.688639, 0.308985, 0.568972]	;
	LowerY = -5	;
	RightX = 10		;
	RGB = RGB5R5Slash6 	;
	patch([RightX-10, RightX-10, RightX, RightX, RightX-10],...
	      [0,LowerY, LowerY, 0, 0],...
	      RGB,...
	      'EdgeColor', RGB);
	hold on
	RightX = 20		;
	RGB = RGB5YR5Slash6 	;
	patch([RightX-10, RightX-10, RightX, RightX, RightX-10],...
	      [0,LowerY, LowerY, 0, 0],...
	      RGB,...
	      'EdgeColor', RGB);
	hold on
	RightX = 30		;
	RGB = RGB5Y5Slash6 	;
	patch([RightX-10, RightX-10, RightX, RightX, RightX-10],...
	      [0,LowerY, LowerY, 0, 0],...
	      RGB,...
	      'EdgeColor', RGB);
	hold on
	RightX = 40		;
	RGB = RGB5GY5Slash6 	;
	patch([RightX-10, RightX-10, RightX, RightX, RightX-10],...
	      [0,LowerY, LowerY, 0, 0],...
	      RGB,...
	      'EdgeColor', RGB);
	hold on
	RightX = 50		;
	RGB = RGB5G5Slash6 	;
	patch([RightX-10, RightX-10, RightX, RightX, RightX-10],...
	      [0,LowerY, LowerY, 0, 0],...
	      RGB,...
	      'EdgeColor', RGB);
	hold on
	RightX = 60		;
	RGB = RGB5BG5Slash6 	;
	patch([RightX-10, RightX-10, RightX, RightX, RightX-10],...
	      [0,LowerY, LowerY, 0, 0],...
	      RGB,...
	      'EdgeColor', RGB);
	hold on
	RightX = 70		;
	RGB = RGB5B5Slash6 	;
	patch([RightX-10, RightX-10, RightX, RightX, RightX-10],...
	      [0,LowerY, LowerY, 0, 0],...
	      RGB,...
	      'EdgeColor', RGB);
	hold on
	RightX = 80		;
	RGB = RGB5PB5Slash6 	;
	patch([RightX-10, RightX-10, RightX, RightX, RightX-10],...
	      [0,LowerY, LowerY, 0, 0],...
	      RGB,...
	      'EdgeColor', RGB);
	hold on
	RightX = 90		;
	RGB = RGB5P5Slash6 	;
	patch([RightX-10, RightX-10, RightX, RightX, RightX-10],...
	      [0,LowerY, LowerY, 0, 0],...
	      RGB,...
	      'EdgeColor', RGB);
	hold on
	RightX = 100		;
	RGB = RGB5RP5Slash6 	;
	patch([RightX-10, RightX-10, RightX, RightX, RightX-10],...
	      [0,LowerY, LowerY, 0, 0],...
	      RGB,...
	      'EdgeColor', RGB);
	hold on
	set(gca, 'xlim', [0 100])					;
	UpperY = 1000 * ceil(max(HueCounts)/1000)	;
	set(gca, 'ylim', [LowerY UpperY])			;

	% Make list of labels for horizontal axis of histogram
	xTicks = EdgeVector(1:2:end)	;
	TickLabels = {}					;
	for ASTMhue = xTicks
		[HueString, HueNumber, HueLetterCode] = ASTMHueToMunsellHue(ASTMhue,0)	;
		TickLabels{end+1} = HueString 											;
	end
	set(gca, 'xtick', xTicks, 'xticklabel', TickLabels)
   	FontName = 'Times New Roman'		;
    LabelFontSizeInPoints = 14	;
    LabelFontWeight = 'normal'	;
    xlabel('Munsell Hue', ...
			 'fontname', FontName, ...
			 'fontweight', LabelFontWeight,...
			 'fontsize', LabelFontSizeInPoints)
    ylabel('Number of Samples',...
			 'fontname', FontName, ...
			 'fontweight', LabelFontWeight,...
			 'fontsize', LabelFontSizeInPoints)

	figname = [NameForOutput,'HueHistogram']	;
	set(gcf, 'Name', figname)
	print(gcf, [figname,'.eps'], '-depsc')		;
	print(gcf, [figname,'.png'], '-dpng')		;
	print(gcf, [figname,'.jpg'], '-djpg')		;
	print(gcf, [figname,'.pdf'], '-dpdf')		;
end

if DisplayValueHistogram
	% Make another histogram, showing how many colours in the set are in different value bands
	ValueBinWidth = 0.5										;
	EdgeVector = [0:ValueBinWidth:100]						;
	ValueCounts = histc(MunsellValuesInList, EdgeVector)	;
	figure
	stairs(EdgeVector, ValueCounts, 'k')					;
	set(gca, 'xlim', [0 10])								;
%	set(gca, 'ylim', [0 40])								;
	set(gca, 'xtick', 1:10)

   	FontName = 'Times New Roman'		;
    LabelFontSizeInPoints = 14	;
    LabelFontWeight = 'normal'	;
    xlabel('Munsell Value', ...
			 'fontname', FontName, ...
			 'fontweight', LabelFontWeight,...
			 'fontsize', LabelFontSizeInPoints)
    ylabel('Number of Samples',...
			 'fontname', FontName, ...
			 'fontweight', LabelFontWeight,...
			 'fontsize', LabelFontSizeInPoints)

	figname = [NameForOutput,'ValueHistogram']	;
	set(gcf, 'Name', figname)
	print(gcf, [figname,'.eps'], '-depsc')		;
	print(gcf, [figname,'.png'], '-dpng')		;
	print(gcf, [figname,'.jpg'], '-djpg')		;
	print(gcf, [figname,'.pdf'], '-dpdf')		;
end

% Identify darkest and lightest colours
[SortedValues, SortedIndices] = sort(transpose(MunsellValuesInList))	;
ColoursToDisplay = 15 	;
% Darkest colours
disp(['Darkest Colours'])
for ctr = 1:ColoursToDisplay
    if exist('NameList')
		disp([num2str(ctr),' ',NameList{SortedIndices(ctr)},...
			  ' (',MunsellList{SortedIndices(ctr)},'): Munsell value ',num2str(SortedValues(ctr))])
    else
		disp([num2str(ctr),' ',MunsellList{SortedIndices(ctr)},': Munsell value ',num2str(SortedValues(ctr))])
	end
end
% Lightest colours
disp(['Lightest Colours'])
for ctr = 1:ColoursToDisplay
    if exist('NameList')
		disp([num2str(ctr),' ',NameList{SortedIndices(end - ctr + 1)},...
			  ' (',MunsellList{SortedIndices(end - ctr + 1)},...
			  '): Munsell value ',num2str(SortedValues(end - ctr + 1))])
    else
		disp([num2str(ctr),' ',MunsellList{SortedIndices(end - ctr + 1)},...
		      ': Munsell value ',num2str(SortedValues(end - ctr + 1))])
	end
end

% Save the sorted values of the samples in a text file, for easy reference
ValueFileName   = [NameForOutput,'SortedValues.txt']	;
NumberOfSamples = size(SortedValues,1)					;
Valuefid        = fopen(ValueFileName, 'w')				;
for ctr = 1:NumberOfSamples
    if exist('NameList')
		OutputLine = sprintf('%s\t%s\t%4.2f', ...
							NameList{SortedIndices(ctr)}, ...
							MunsellList{SortedIndices(ctr)}, ...
							SortedValues(ctr))	;
	else
		OutputLine = sprintf('%s\t%4.2f', ...
							MunsellList{SortedIndices(ctr)}, ...
							SortedValues(ctr))	;
	end
	if ctr ~= NumberOfSamples	% Add a return character after each line except the last
		fprintf(Valuefid, '%s\n', OutputLine)	;
	else						% No return after last line, to avoid blank line at end of file
		fprintf(Valuefid, '%s', OutputLine)	;
	end							
end
fclose(Valuefid)	;


if DisplayChromaHistogram
	% Make another histogram, showing how many colours in the set are in different value bands
	ChromaBinWidth = 1										;
	EdgeVector = [0:ChromaBinWidth:20]						;
	ChromaCounts = histc(MunsellChromasInList, EdgeVector)	;
	figure
	stairs(EdgeVector, ChromaCounts, 'k')					;
	set(gca, 'xlim', [0 22])								;
%	set(gca, 'ylim', [0 60])								;
	set(gca, 'xtick', 0:2:20)

   	FontName = 'Times New Roman'		;
    LabelFontSizeInPoints = 14	;
    LabelFontWeight = 'normal'	;
    xlabel('Munsell Chroma', ...
			 'fontname', FontName, ...
			 'fontweight', LabelFontWeight,...
			 'fontsize', LabelFontSizeInPoints)
    ylabel('Number of Samples',...
			 'fontname', FontName, ...
			 'fontweight', LabelFontWeight,...
			 'fontsize', LabelFontSizeInPoints)

	figname = [NameForOutput,'ChromaHistogram']	;
	set(gcf, 'Name', figname)
	print(gcf, [figname,'.eps'], '-depsc')		;
	print(gcf, [figname,'.png'], '-dpng')		;
	print(gcf, [figname,'.jpg'], '-djpg')		;
	print(gcf, [figname,'.pdf'], '-dpdf')		;
end

% Identify least and most saturated colours
[SortedChromas, SortedIndices] = sort(transpose(MunsellChromasInList))	;
ColoursToDisplay = 20 	;
% Least saturated colours
disp(['Least saturated Colours'])
for ctr = 1:ColoursToDisplay
    if exist('NameList')
		disp([num2str(ctr),' ',NameList{SortedIndices(ctr)},...
			  ' (',MunsellList{SortedIndices(ctr)},'): Munsell chroma ',num2str(SortedChromas(ctr))])
    else
		disp([num2str(ctr),' ',MunsellList{SortedIndices(ctr)},': Munsell chroma ',num2str(SortedChromas(ctr))])
	end
end
% Most saturated colours
disp(['Most saturated Colours'])
for ctr = 1:ColoursToDisplay
    if exist('NameList')
		disp([num2str(ctr),' ',NameList{SortedIndices(end - ctr + 1)},...
			  ' (',MunsellList{SortedIndices(end - ctr + 1)},...
			  '): Munsell chroma ',num2str(SortedChromas(end - ctr + 1))])
    else
		disp([num2str(ctr),' ',MunsellList{SortedIndices(end - ctr + 1)},...
		      ': Munsell chroma ',num2str(SortedChromas(end - ctr + 1))])
	end
end

% Save the sorted chromas of the samples in a text file, for easy reference
ChromaFileName  = [NameForOutput,'SortedChromas.txt']	;
NumberOfSamples = size(SortedValues,1)					;
Chromafid       = fopen(ChromaFileName, 'w')				;
for ctr = 1:NumberOfSamples
    if exist('NameList')
		OutputLine = sprintf('%s\t%s\t%4.2f', ...
							NameList{SortedIndices(ctr)}, ...
							MunsellList{SortedIndices(ctr)}, ...
							SortedChromas(ctr))	;
	else
		OutputLine = sprintf('%s\t%4.2f', ...
							MunsellList{SortedIndices(ctr)}, ...
							SortedChromas(ctr))	;
	end
							
	if ctr ~= NumberOfSamples	% Add a return character after each line except the last
		fprintf(Chromafid, '%s\n', OutputLine)	;
	else						% No return after last line, to avoid blank line at end of file
		fprintf(Chromafid, '%s', OutputLine)	;
	end							
end
fclose(Chromafid)	;

if CheckForNearDuplicates
	% Check for duplicates or near-duplicates by calculating the DEs between all possible pairs.
	% Investigate the pairs with the smallest DEs, to see how easily distinguishable they are.
	% First, convert the Munsell specifications to CIE xyY coordinates.  To reduce runtime,
	% save the xyY coordinates once they are found, and reload them in subsequent runs, 
	% to avoid recalculation.
	SavedxyYFile = [NameForOutput,'xyY.mat']	;
	if ~isempty(which(SavedxyYFile))
		load(SavedxyYFile)	;
	else
		xyY = [] 	;	% List of CIE xyY coordinates that correspond to Munsell inputs
		for ctr = 1:NumOfColours
			[x y Y Status] = MunsellToxyY(MunsellList{ctr});
			xyY(ctr,:) = [x y Y]	;
		end
		save(SavedxyYFile, 'xyY')	;
	end

	% Then, calculate the DEs over all pairs.  As before, save off the pairs and DEs after
	% the first time they are calculated, and reload them on subsequent runs
	WhitePointXYZ = WhitePointWithYEqualTo100('C/2')	;
	SavedDEFile = [NameForOutput,'DEs.mat']	;
	if ~isempty(which(SavedDEFile))
		load(SavedDEFile)	;
	else
		PairsAndDEs = []	;
		for ctr1 = 1:(NumOfColours-1)
			for ctr2 = (ctr1+1):NumOfColours
				DE2000 = CIEDE2000ForxyY(xyY(ctr1,:), xyY(ctr2,:), WhitePointXYZ, [1 1 1])	;
				PairsAndDEs = [PairsAndDEs; ctr1 ctr2 DE2000]	;
			end
		end
		save(SavedDEFile,'PairsAndDEs')
	end

	% Sort the pairs from lowest DE to smallest.  Pairs with very small DEs are duplicates,
	% or nearly so.  Display them for further investigation, and save them to a file  
	SortedDEs = sortrows(PairsAndDEs, 3)	;
	disp(['Closest matches'])
	for ctr = 1:min(40,size(SortedDEs,1))
		DisplayString = sprintf('%d\t%s\t%s\t%4.2f\t%s vs %s', ...
								ctr, ...
								NameList{SortedDEs(ctr,1)}, ...
								NameList{SortedDEs(ctr,2)}, ...
								SortedDEs(ctr,3), ...
								MunsellList{SortedDEs(ctr,1)}, ...
								MunsellList{SortedDEs(ctr,2)})	;
		disp(DisplayString)						
	end

	% Save the list of DEs for all pairs in a text file, for easy reference
	DEFileName    = [NameForOutput,'DEsForPairs.txt']	;
	NumberOfPairs = size(PairsAndDEs,1)					;
	DEfid         = fopen(DEFileName, 'w')				;
	for ctr = 1:NumberOfPairs
		OutputLine = sprintf('%s\t%s\t%4.2f\t%s\t%s', ...
								NameList{SortedDEs(ctr,1)}, ...
								NameList{SortedDEs(ctr,2)}, ...
								SortedDEs(ctr,3), ...
								MunsellList{SortedDEs(ctr,1)}, ...
								MunsellList{SortedDEs(ctr,2)})	;
		if ctr ~= NumberOfPairs		% Add a return character after each line except the last
			fprintf(DEfid, '%s\n', OutputLine)	;
		else						% No return after last line, to avoid blank line at end of file
			fprintf(DEfid, '%s', OutputLine)	;
		end							
	end
	fclose(DEfid)	;
end

if DisplayMunsellHueLeaves
PageBoundaries = 0:10:100	;
for pagectr = 1:(length(PageBoundaries) - 1)
    if pagectr == 1 % Include ASTM hue 0 in first page
		IndicesToPlot = find(ASTMHuesInList <= PageBoundaries(pagectr+1))		;
    else
		IndicesToPlot = intersect(find(PageBoundaries(pagectr) < ASTMHuesInList), ...
							      find(ASTMHuesInList <= PageBoundaries(pagectr+1)))	;
    end
    ValuesToPlot  = MunsellValuesInList(IndicesToPlot)		;
    ChromasToPlot = MunsellChromasInList(IndicesToPlot)		;
    
    figure
%    plot(ChromasToPlot, ValuesToPlot, 'k*')   	% Plot markers if desired, for colours

	% It might be desired to display colour names on the plots, in addition to, or perhaps
	% instead of, just the markers.  
    if exist('NameList')		% Write colour names on plot, if desired
    	% For a particular set of colours, adjustments might have to be made manually, to
    	% avoid printing two names in the same location. (This can happen when two colours
    	% are very similar to each other.)
    	SizeOfFontInPoints = 6 	;
    	FontWeight = 'bold' 	;
    	FontName = 'Times New Roman'		;
        if strcmp(NameForOutput, 'Unison')
            if pagectr == 1		% Each plot might need special additions
				ValueOffset = 0.0	;
				ChromaOffset = 0.0	;
				for index = IndicesToPlot
					hold on
					if ~strcmp(NameList{index}, 'BE8') && ...
					   ~strcmp(NameList{index}, 'BE26') && ...
					   ~strcmp(NameList{index}, 'A17') && ...
					   ~strcmp(NameList{index}, 'R10') && ...
					   ~strcmp(NameList{index}, 'J2') && ...
					   ~strcmp(NameList{index}, 'J3') && ...
					   ~strcmp(NameList{index}, 'J4') 
						text(MunsellChromasInList(index)+ChromaOffset, ...
							 MunsellValuesInList(index)+ValueOffset, ...
							 NameList{index},...
							 'fontname', FontName, ...
							 'fontweight', FontWeight,...
							 'fontsize', SizeOfFontInPoints)
					end
				end
				 
				% Print duplicates specially
				hold on
				text(4.8+ChromaOffset, ...
					 7.4+ValueOffset, ...
					 'BE8/BE26',...
					 'fontname', FontName, ...
					 'fontweight', FontWeight,...
					 'fontsize', SizeOfFontInPoints)
				hold on
				text(10.7+ChromaOffset, ...
					 5.8+ValueOffset, ...
					 'A17/R10/J4',...
					 'fontname', FontName, ...
					 'fontweight', FontWeight,...
					 'fontsize', SizeOfFontInPoints)
				hold on
				text(8.7+ChromaOffset, ...
					 5.1+ValueOffset, ...
					 'J2/J3',...
					 'fontname', FontName, ...
					 'fontweight', FontWeight,...
					 'fontsize', SizeOfFontInPoints)
		    elseif pagectr == 2
				ValueOffset = 0.0	;
				ChromaOffset = 0.0	;
				for index = IndicesToPlot
					hold on
					if ~strcmp(NameList{index}, 'SC1') && ...
					   ~strcmp(NameList{index}, 'O7') && ...
					   ~strcmp(NameList{index}, 'SC2') && ...
					   ~strcmp(NameList{index}, 'Y7') && ...
					   ~strcmp(NameList{index}, 'BE12') && ...
					   ~strcmp(NameList{index}, 'RE17') && ...
					   ~strcmp(NameList{index}, 'BE22') && ...
					   ~strcmp(NameList{index}, 'NE10') && ...
					   ~strcmp(NameList{index}, 'Dark3') && ...
					   ~strcmp(NameList{index}, 'BE6') && ...
					   ~strcmp(NameList{index}, 'BE8') && ...
					   ~strcmp(NameList{index}, 'BE26') && ...
					   ~strcmp(NameList{index}, 'NE3') && ...
					   ~strcmp(NameList{index}, 'RE15') && ...
					   ~strcmp(NameList{index}, 'O12') && ...
					   ~strcmp(NameList{index}, 'Port5') 
						text(MunsellChromasInList(index)+ChromaOffset, ...
							 MunsellValuesInList(index)+ValueOffset, ...
							 NameList{index},...
							 'fontname', FontName, ...
							 'fontweight', FontWeight,...
							 'fontsize', SizeOfFontInPoints)
					end
				end
				 
				% Print duplicates specially
				hold on
				text(15.5+ChromaOffset, ...
					 6.1+ValueOffset, ...
					 'SC1/O7',...
					 'fontname', FontName, ...
					 'fontweight', FontWeight,...
					 'fontsize', SizeOfFontInPoints)
				hold on
				text(13.2+ChromaOffset, ...
					 6.6+ValueOffset, ...
					 'Y7/SC2',...
					 'fontname', FontName, ...
					 'fontweight', FontWeight,...
					 'fontsize', SizeOfFontInPoints)
				hold on
				text(6.2+ChromaOffset, ...
					 3.9+ValueOffset, ...
					 'BE12/RE17',...
					 'fontname', FontName, ...
					 'fontweight', FontWeight,...
					 'fontsize', SizeOfFontInPoints)
				hold on
				text(3.5+ChromaOffset, ...
					 5.2+ValueOffset, ...
					 'BE22/NE10',...
					 'fontname', FontName, ...
					 'fontweight', FontWeight,...
					 'fontsize', SizeOfFontInPoints)
				hold on
				text(1.9+ChromaOffset, ...
					 2.7+ValueOffset, ...
					 'BE6/Dark3',...
					 'fontname', FontName, ...
					 'fontweight', FontWeight,...
					 'fontsize', SizeOfFontInPoints)
				hold on
				text(4.6+ChromaOffset, ...
					 7.4+ValueOffset, ...
					 'BE26/BE8',...
					 'fontname', FontName, ...
					 'fontweight', FontWeight,...
					 'fontsize', SizeOfFontInPoints)
				hold on
				text(6.0+ChromaOffset, ...
					 5.7+ValueOffset, ...
					 'RE15/NE3',...
					 'fontname', FontName, ...
					 'fontweight', FontWeight,...
					 'fontsize', SizeOfFontInPoints)
				hold on
				text(4.7+ChromaOffset, ...
					 8.4+ValueOffset, ...
					 'P5/O12',...
					 'fontname', FontName, ...
					 'fontweight', FontWeight,...
					 'fontsize', SizeOfFontInPoints)
		    elseif pagectr == 3
				ValueOffset = 0.0	;
				ChromaOffset = 0.0	;
				for index = IndicesToPlot
					hold on
					if ~strcmp(NameList{index}, 'Light2') && ...
					   ~strcmp(NameList{index}, 'Light3') && ...
					   ~strcmp(NameList{index}, 'NE15') && ...
					   ~strcmp(NameList{index}, 'BE3') && ...
					   ~strcmp(NameList{index}, 'YGE16') && ...
					   ~strcmp(NameList{index}, 'BE27') && ...
					   ~strcmp(NameList{index}, 'Grey25') && ...
					   ~strcmp(NameList{index}, 'Grey24') 
						text(MunsellChromasInList(index)+ChromaOffset, ...
							 MunsellValuesInList(index)+ValueOffset, ...
							 NameList{index},...
							 'fontname', FontName, ...
							 'fontweight', FontWeight,...
							 'fontsize', SizeOfFontInPoints)
					end
				end
				 
				% Print duplicates specially
				hold on
				text(3.7+ChromaOffset, ...
					 9.2+ValueOffset, ...
					 'Light2/Light3',...
					 'fontname', FontName, ...
					 'fontweight', FontWeight,...
					 'fontsize', SizeOfFontInPoints)
				hold on
				text(6.6+ChromaOffset, ...
					 3.6+ValueOffset, ...
					 'NE15/BE3',...
					 'fontname', FontName, ...
					 'fontweight', FontWeight,...
					 'fontsize', SizeOfFontInPoints)
				hold on
				text(4.7+ChromaOffset, ...
					 5.9+ValueOffset, ...
					 'BE27/YGE16',...
					 'fontname', FontName, ...
					 'fontweight', FontWeight,...
					 'fontsize', SizeOfFontInPoints)
				hold on
				text(2.2+ChromaOffset, ...
					 8.7+ValueOffset, ...
					 'Grey25/Grey24',...
					 'fontname', FontName, ...
					 'fontweight', FontWeight,...
					 'fontsize', SizeOfFontInPoints)
		    elseif pagectr == 4
				ValueOffset = 0.0	;
				ChromaOffset = 0.0	;
				for index = IndicesToPlot
					hold on
					if ~strcmp(NameList{index}, 'Dark11') && ...
					   ~strcmp(NameList{index}, 'Dark12') 
						text(MunsellChromasInList(index)+ChromaOffset, ...
							 MunsellValuesInList(index)+ValueOffset, ...
							 NameList{index},...
							 'fontname', FontName, ...
							 'fontweight', FontWeight,...
							 'fontsize', SizeOfFontInPoints)
					end
				end
				 
				% Print duplicates specially
				hold on
				text(3.7+ChromaOffset, ...
					 3.8+ValueOffset, ...
					 'Dark12/Dark11',...
					 'fontname', FontName, ...
					 'fontweight', FontWeight,...
					 'fontsize', SizeOfFontInPoints)
			elseif pagectr == 5
				ValueOffset = 0.0	;
				ChromaOffset = 0.0	;
				for index = IndicesToPlot
					hold on
					if ~strcmp(NameList{index}, 'Dark10') && ...
					   ~strcmp(NameList{index}, 'G1') && ...
					   ~strcmp(NameList{index}, 'G3') && ...
					   ~strcmp(NameList{index}, 'YGE5') && ...
					   ~strcmp(NameList{index}, 'YGE4') 
						text(MunsellChromasInList(index)+ChromaOffset, ...
							 MunsellValuesInList(index)+ValueOffset, ...
							 NameList{index},...
							 'fontname', FontName, ...
							 'fontweight', FontWeight,...
							 'fontsize', SizeOfFontInPoints)
					end
				end
				 
				% Print duplicates specially
				hold on
				text(3.4+ChromaOffset, ...
					 3.4+ValueOffset, ...
					 'Dark10/G1',...
					 'fontname', FontName, ...
					 'fontweight', FontWeight,...
					 'fontsize', SizeOfFontInPoints)
				hold on
				text(2.5+ChromaOffset, ...
					 5.4+ValueOffset, ...
					 'YGE5/G3',...
					 'fontname', FontName, ...
					 'fontweight', FontWeight,...
					 'fontsize', SizeOfFontInPoints)
				hold on
				text(1.8+ChromaOffset, ...
					 6.2+ValueOffset, ...
					 'YGE4',...
					 'fontname', FontName, ...
					 'fontweight', FontWeight,...
					 'fontsize', SizeOfFontInPoints)
		    elseif pagectr == 6
				ValueOffset = 0.0	;
				ChromaOffset = 0.0	;
				for index = IndicesToPlot
					hold on
					if ~strcmp(NameList{index}, 'Dark7') && ...
					   ~strcmp(NameList{index}, 'A43') 
						text(MunsellChromasInList(index)+ChromaOffset, ...
							 MunsellValuesInList(index)+ValueOffset, ...
							 NameList{index},...
							 'fontname', FontName, ...
							 'fontweight', FontWeight,...
							 'fontsize', SizeOfFontInPoints)
					end
				end
				 
				% Print duplicates specially
				hold on
				text(1.6+ChromaOffset, ...
					 2.7+ValueOffset, ...
					 'A43/Dark7',...
					 'fontname', FontName, ...
					 'fontweight', FontWeight,...
					 'fontsize', SizeOfFontInPoints)
		    elseif pagectr == 7
				ValueOffset = 0.0	;
				ChromaOffset = 0.0	;
				for index = IndicesToPlot
					hold on
					if ~strcmp(NameList{index}, 'Dark16') && ...
					   ~strcmp(NameList{index}, 'A49') && ...
					   ~strcmp(NameList{index}, 'BG10') && ...
					   ~strcmp(NameList{index}, 'T5') 
						text(MunsellChromasInList(index)+ChromaOffset, ...
							 MunsellValuesInList(index)+ValueOffset, ...
							 NameList{index},...
							 'fontname', FontName, ...
							 'fontweight', FontWeight,...
							 'fontsize', SizeOfFontInPoints)
					end
				end
				 
				% Print duplicates specially
				hold on
				text(1.9+ChromaOffset, ...
					 1.9+ValueOffset, ...
					 'A49/Dark16',...
					 'fontname', FontName, ...
					 'fontweight', FontWeight,...
					 'fontsize', SizeOfFontInPoints)
				hold on
				text(6.4+ChromaOffset, ...
					 7.3+ValueOffset, ...
					 'BG10/T5',...
					 'fontname', FontName, ...
					 'fontweight', FontWeight,...
					 'fontsize', SizeOfFontInPoints)
		    elseif pagectr == 8
				ValueOffset = 0.0	;
				ChromaOffset = 0.0	;
				for index = IndicesToPlot
% disp([NameList{index},'  ',num2str(MunsellValuesInList(index)),'/',num2str(MunsellChromasInList(index))])
					hold on
					if ~strcmp(NameList{index}, 'BV7') && ...
					   ~strcmp(NameList{index}, 'A1') 
						text(MunsellChromasInList(index)+ChromaOffset, ...
							 MunsellValuesInList(index)+ValueOffset, ...
							 NameList{index},...
							 'fontname', FontName, ...
							 'fontweight', FontWeight,...
							 'fontsize', SizeOfFontInPoints)
					end
				end
				 
				% Print duplicates specially
				hold on
				text(2.2+ChromaOffset, ...
					 8.6+ValueOffset, ...
					 'A1/BV7',...
					 'fontname', FontName, ...
					 'fontweight', FontWeight,...
					 'fontsize', SizeOfFontInPoints)
		    elseif pagectr == 9
				ValueOffset = 0.0	;
				ChromaOffset = 0.0	;
				for index = IndicesToPlot
					hold on
					if ~strcmp(NameList{index}, 'BE8') && ...
					   ~strcmp(NameList{index}, 'BE26') && ...
					   ~strcmp(NameList{index}, 'A17') && ...
					   ~strcmp(NameList{index}, 'R10') && ...
					   ~strcmp(NameList{index}, 'J2') && ...
					   ~strcmp(NameList{index}, 'J3') && ...
					   ~strcmp(NameList{index}, 'J4') 
						text(MunsellChromasInList(index)+ChromaOffset, ...
							 MunsellValuesInList(index)+ValueOffset, ...
							 NameList{index},...
							 'fontname', FontName, ...
							 'fontweight', FontWeight,...
							 'fontsize', SizeOfFontInPoints)
					end
				end
		    elseif pagectr == 10
				ValueOffset = 0.0	;
				ChromaOffset = 0.0	;
				for index = IndicesToPlot
					hold on
					if ~strcmp(NameList{index}, 'BE8') && ...
					   ~strcmp(NameList{index}, 'BE26') && ...
					   ~strcmp(NameList{index}, 'A17') && ...
					   ~strcmp(NameList{index}, 'R10') && ...
					   ~strcmp(NameList{index}, 'J2') && ...
					   ~strcmp(NameList{index}, 'J3') && ...
					   ~strcmp(NameList{index}, 'J4') 
						text(MunsellChromasInList(index)+ChromaOffset, ...
							 MunsellValuesInList(index)+ValueOffset, ...
							 NameList{index},...
							 'fontname', FontName, ...
							 'fontweight', FontWeight,...
							 'fontsize', SizeOfFontInPoints)
					end
				end
			end
        else 	% No manual adjustments are to be made (there is no list of names)
			ValueOffset = 0.0	;
			ChromaOffset = 0.0	;
			for index = IndicesToPlot
				hold on
				text(MunsellChromasInList(index)+ChromaOffset, ...
					 MunsellValuesInList(index)+ValueOffset, ...
					 NameList{index},...
					 'fontname', FontName, ...
					 'fontweight', FontWeight,...
					 'fontsize', SizeOfFontInPoints)
			end
    	end
    end
    set(gca, 'DataAspectRatio', [2.3, 1, 1])
    set(gca, 'xlim', [0 18])
    set(gca, 'ylim', [1.5 9.5])
    set(gca, 'ytick', 2:9)
    LabelFontSizeInPoints = 12	;
    LabelFontWeight = 'normal'	;
    xlabel('Munsell Chroma', ...
			 'fontname', FontName, ...
			 'fontweight', LabelFontWeight,...
			 'fontsize', LabelFontSizeInPoints)
%    set(gca, 'xlabel', 'Munsell Chroma')
    ylabel('Munsell Value',...
			 'fontname', FontName, ...
			 'fontweight', LabelFontWeight,...
			 'fontsize', LabelFontSizeInPoints)
    
	figname = [NameForOutput,'MunsellPage',num2str(pagectr)]	;
	set(gcf, 'Name', figname)
	print(gcf, [figname,'.eps'], '-depsc')		;
	print(gcf, [figname,'.png'], '-dpng')		;
	print(gcf, [figname,'.jpg'], '-djpg')		;
	print(gcf, [figname,'.pdf'], '-dpdf')		;
end
end