treeCount = Rows ("Tree");

if (treeCount > 0)
{
	treeChoices = {treeCount,2};
	for (k=0; k<treeCount; k=k+1)
	{
		GetString (treeID, Tree, k);
		treeChoices [k][0] = treeID;
		treeChoices [k][1] = "Tree " + treeID;
	}
	
	chosenTree = 0;
	if (treeCount > 1)
	{
		ChoiceList (chosenTree, "Which tree?", 1, SKIP_NONE, treeChoices);
		if (chosenTree < 0)
		{
			return;
		}
	}
	
	LoadFunctionLibrary("TreeFunctions");
	
	computeMultFactors  (treeChoices[chosenTree][0]);


	divInfo 		=	 computeTotalDivergence (treeChoices[chosenTree][0]);
	pInfo 			= 	2*divInfo[0]/leafCount/(leafCount-1);
	currentDepth	= 	divInfo[1]/(Abs(treeAVL2)-2);
	
	fprintf (stdout, "Mean pairwise divergence for ",treeChoices[chosenTree][0], " is ", pInfo, 	   "\n");
	fprintf (stdout, "Mean branch length for ",      treeChoices[chosenTree][0], " is ", currentDepth, "\n");

	lf_Count						    = Rows ("LikelihoodFunction");
	if (lf_Count > 0)
	{
		for (lf_ID = 0; lf_ID < lf_Count; lf_ID = lf_ID + 1)
		{
			GetString (treeID, LikelihoodFunction,lf_ID);
			GetString(lfInfo,^treeID,-1);
			lfTrees = lfInfo["Trees"];
			for (k = 0; k<Columns(lfTrees); k=k+1)
			{
				if (lfTrees[k] == treeChoices[chosenTree][0])
				{
					break;
				}
			}
			if (k < Columns(lfTrees))
			{
				fprintf (stdout, "\nTree ",Columns(lfTrees)," is a part of likelihood function ", treeID, "\n");
				global			TreeScalerParameter = 1;
				COVARIANCE_PARAMETER = "TreeScalerParameter";
				ExecuteCommands	("ClearConstraints("+treeChoices[chosenTree][0]+");ReplicateConstraint (\"this1.?.?:=TreeScalerParameter*this2.?.?__\","+treeChoices[chosenTree][0]+","+treeChoices[chosenTree][0]+");\n");
				
				COVARIANCE_PRECISION = 0.95;
				ExecuteCommands ("CovarianceMatrix(cmx,"+treeID+");");
				fprintf (stdout, "\nMultiplicative range ", cmx[0], "-", cmx[2], "\n");
				fprintf (stdout, "Mean pairwise divergence: ", pInfo, " (", pInfo*cmx[0],",",pInfo*cmx[2],")\n");
				fprintf (stdout, "Mean branch length divergence: ", currentDepth, " (", currentDepth*cmx[0],",",currentDepth*cmx[2],")\n");
				
				return {"MEAN PAIRWISE DIVERGENCE": {{pInfo, pInfo*cmx[0], pInfo*cmx[2]}},
						"MEAN BRANCH LENGTH": {{currentDepth, currentDepth*cmx[0],currentDepth*cmx[2]}}}; 
			}
		}
	}
	
}

