selLabelMatrix = {{"Model","Log(L)","#parameters","AIC","cAIC","BIC", "Tree length"}};

PModel_ResultTable = {};
PModel_ResultTable ["Model"] 		 = "TEXT";
PModel_ResultTable ["MIndex"]     	 = "INTEGER";		
PModel_ResultTable ["Freqs"]     	 = "INTEGER";		
PModel_ResultTable ["LogL"]    		 = "REAL";
PModel_ResultTable ["params"]    	 = "INTEGER";
PModel_ResultTable ["AIC"]    		 = "REAL";
PModel_ResultTable ["cAIC"]    	 	 = "REAL";
PModel_ResultTable ["BIC"]    	 	 = "REAL";
PModel_ResultTable ["T"]     		 = "REAL";		


/*___________________________________________________________________________________________________________*/

function	PrintASCIITable (dataMatrix, titleMatrix, aic, caic, bic)
{
	outString="";
	outString*8192;
	if (Rows(dataMatrix))
	{
		outString*"<DIV CLASS='RepClassSM'>\n<TABLE BORDER = '0'><TR CLASS='TRReport' style = 'font-size:10px;'>";
		nc = Columns(titleMatrix);
		outString*("<td style='text-align:left;'></td>");
		outString*("<td style='text-align:left;'><a href = '"+BASE_CGI_URL_STRING+"aamodels.pl' class = 'INFO'>");
		outString*titleMatrix[0];
		outString*"</a></td>\n";
		for (counter1=1; counter1<nc; counter1 = counter1+1)
		{
			outString*"<td>";
			outString*titleMatrix[counter1];
			outString*"</td>\n";
		}
		
		outString*"</tr>\n";
		
		for (counter1=0; counter1<Rows(dataMatrix); counter1 = counter1 + 1)
		{
			if (counter1%2)
			{
				outString*"\n<tr CLASS='TRReport2' style = 'font-size:10px;'>";
			}
			else
			{
				outString*"\n<tr CLASS='TRReport1' style = 'font-size:10px;'>";
			}
			
			outString*"\n<td style='text-align:left;'>";
			outString* (""+(counter1+1));
			outString*"\n</td>\n";

			outString*"\n<td style='text-align:left;'>";
			outString*makeModelName(dataMatrix[counter1][0],dataMatrix[counter1][1]);
			outString*"\n</td>\n";

			for (counter2 = 2; counter2 <= nc; counter2 = counter2+1)
			{
				if (counter2 == 4)
				{
					rgbColor = (256*(1-Exp((aic-dataMatrix[counter1][4])/2)))$1;
					outString * ("<td style='background-color:RGB(255,"+rgbColor+","+rgbColor+");'>");
				}
				else
				{
					if (counter2 == 5)
					{
						rgbColor = (256*(1-Exp((caic-dataMatrix[counter1][5])/2)))$1;
						outString * ("<td style='background-color:RGB(255,"+rgbColor+","+rgbColor+");'>");
					}
					else
					{
						if (counter2 == 6)
						{
							rgbColor = (256*(1-Exp((bic-dataMatrix[counter1][6])/2)))$1;
							outString * ("<td style='background-color:RGB(255,"+rgbColor+","+rgbColor+");'>");
						}
						else
						{
							outString*"\n<td>";
						}
					}
				}
				outString*Format(dataMatrix[counter1][counter2],-1,-1);
				outString*"\n</td>\n";
			}
			
			outString*"</tr>\n";
		}
		outString*"</TABLE></DIV>\n";	
	}
	outString*0;
	return outString;
}

/*___________________________________________________________________________________________________________*/

function	makeModelName (i, f)
{
	modelName = (modelList[i])["Name"];
	if (f)
	{
		modelName = modelName + "+F";
	}
	return modelName;
}
