/**
Update Component modifications from Creo to CyPhy (Creo Update (Export)).

Pre-conditions:
 * MetaLink is running and CyPhy and CAD-assebler are connected
 * Creo is opened in AVM component editing mode.
   - CyPhy switches Creo to AVM component editing mode.
   - CyPhy starts CAD-assembler in component editing mode.
Action:
 * Perform AVM component edits in Creo
   - add a datum
   - modify a parameter
 * Press the “Update Cyphy Component” button.
Post-condition:
 * The updates are reflected in the CyPhy component.

*/
ProError DoUpdateComponent()
{
	ProError status = PRO_TK_NO_ERROR; 
	ProMdlType type;
	wchar_t msg[1000];
	ProMdl mdl;
	*msg = 0;

	if (isis::GlobalModelData::Instance.mode == isis::COMPONENTEDIT)
	{
		ProMdlCurrentGet(&mdl);
	} else {
		mdl = getSelectedMdl();
	}

	if (!mdl)
	{
		ErrorDialog(L"No model has been selected.");
		return status;
	}
	ProMdlTypeGet(mdl, &type);
	if (type != PRO_MDL_PART && type != PRO_MDL_ASSEMBLY)
	{
		ErrorDialog(L"Selected model has to be either part or assembly.");
		return status;
	}

	UpdateComponent(mdl);

	return status;
}
void AACodonMutSelSBDPPhyloProcess::SlaveComputeCVScore()	{

	int sitemin = GetSiteMin();
	int sitemax = GetSiteMin() + testsitemax - testsitemin;
	double** sitelogl = new double*[ProfileProcess::GetNsite()];
	for (int i=sitemin; i<sitemax; i++)	{
		sitelogl[i] = new double[GetNcomponent()];
	}
	
	for (int k=0; k<GetNcomponent(); k++)	{
		for (int i=sitemin; i<sitemax; i++)	{
			AACodonMutSelSBDPProfileProcess::alloc[i] = k;
		}
		UpdateComponent(k);
		UpdateConditionalLikelihoods();
		for (int i=sitemin; i<sitemax; i++)	{
			sitelogl[i][k] = sitelogL[i];
		}
	}

	double total = 0;
	for (int i=sitemin; i<sitemax; i++)	{
		double max = 0;
		for (int k=0; k<GetNcomponent(); k++)	{
			if ((!k) || (max < sitelogl[i][k]))	{
				max = sitelogl[i][k];
			}
		}
		double tot = 0;
		double totweight = 0;
		for (int k=0; k<GetNcomponent(); k++)	{
			tot += weight[k] * exp(sitelogl[i][k] - max);
			totweight += weight[k];
		}
		total += log(tot) + max;
	}

	MPI_Send(&total,1,MPI_DOUBLE,0,TAG1,MPI_COMM_WORLD);
	
	for (int i=sitemin; i<sitemax; i++)	{
		delete[] sitelogl[i];
	}
	delete[] sitelogl;
}