if (NON_EMPTY_SELECTION)
{
	data_rows  	 		= Columns 	(SELECTED_CHART_ROWS);
	selected_columns	= {data_rows, 1};
	different_columns	= 0;
	first_row			= SELECTED_CHART_ROWS[0];
	counter				= 0;

	while ((counter<data_rows)&&(SELECTED_CHART_ROWS[counter]==first_row))
	{
		selected_columns [different_columns] = SELECTED_CHART_COLS[counter];
		different_columns = different_columns+1;
		counter = counter + 1;
	}

	column_stensil = {different_columns,1};

	for (counter=0; counter < different_columns; counter = counter + 1)
	{
		column_stensil [counter] = selected_columns[counter];
	}

	selected_columns = 0;

	/*check selection consistency*/

	counter = different_columns; 

	while (counter+different_columns < data_rows)
	{
		first_row			= SELECTED_CHART_ROWS[counter];
		for (counter2 = 0; counter2 < different_columns; counter2 = counter2 + 1)
		{		
			if ((SELECTED_CHART_COLS[counter2+counter]==column_stensil[counter2])&&(SELECTED_CHART_ROWS[counter2+counter]==first_row))
			{
				continue;
			}
			break;
		}
		if (counter2 != different_columns)
		{
			counter = -1;
			break;
		}
		counter = counter+different_columns;
	}

	if (counter+different_columns!=data_rows)
	{
		fprintf (stdout, "Invalid selection: the same rows must be selected in each column\n");
	}
	else
	{
		cell_selector = "";
		while (Abs(cell_selector) == 0)
		{
			fprintf (stdout, "\nSelection criterion in terms of cell_value[index], where index is between 0 and ", 
								different_columns-1,":");
								
			fscanf  (stdin,  "String", cell_selector);
		}
		
		ExecuteCommands ("cell_selector:="+cell_selector+";");
		cell_value 		= {different_columns,1};
		selectedData    = {data_rows,different_columns+1};
		actualSelected  = 0;

		for (counter=0; counter < data_rows; counter = counter+different_columns)
		{
			for (counter2 = 0; counter2 < different_columns; counter2 = counter2 + 1)
			{
				cell_value[counter2] = SELECTED_CHART_DATA[counter+counter2];
			}
			
			if (cell_selector)
			{
				selectedData [actualSelected][0] = SELECTED_CHART_ROWS[counter]+1;			
				for (counter2 = 0; counter2 < different_columns; counter2 = counter2 + 1)
				{
					selectedData [actualSelected][counter2+1] = SELECTED_CHART_DATA[counter+counter2];
				}
				actualSelected = actualSelected + 1;			
			}
		}
		
		if (actualSelected == 0)
		{
			fprintf (stdout, "\nNo cells matched selection criteria\n");
		}
		else
		{
			reallySelectedData = {actualSelected,different_columns+1};
			
			labels = {1,different_columns+1};
			labels[0] = "Cell Index";
			
			for (count = 0; count < actualSelected; count = count + 1)
			{
				for (counter2 = 0; counter2 <= different_columns; counter2 = counter2+1)
				{
					reallySelectedData[count][counter2] = selectedData[count][counter2];
				}
			}

			for (counter2 = 1; counter2 <= different_columns; counter2 = counter2+1)
			{
				count = column_stensil[counter2-1];
				labels[counter2] = CHART_COLUMN_HEADERS[count];
			}
			
			fprintf (stdout, "\nMatched ", Rows(reallySelectedData)," rows\n");
			
			selectedData = "Selected Data";
			OpenWindow (CHARTWINDOW,{{selectedData}
								   {"labels"},
								   {"reallySelectedData"},
								   {"Bar Chart"},
								   {labels[0]},
								   {labels[1]},
								   {"Index"},
								   {""},
								   {"Value"},
								   {"0"}
								   {""}
								   {"-1;-1"}
								   {"10;1.309;0.785398"}
								   {"Times:12:0;Times:10:0;Times:12:2"}
								   {"0;0;13816530;16777215;0;0;6579300;11842740;13158600;14474460;0;3947580;16777215;15670812;6845928;16771158;2984993;9199669;7018159;1460610;16748822;11184810;14173291"}
								   {"16"}
								   },
								   "SCREEN_WIDTH-60;SCREEN_HEIGHT-50;30;50");
		}
	}
}
else
{
	NON_EMPTY_SELECTION = -1;
}
