number Alin1 =1		,Mgin1 =0		,Oin1 =0
number Alin2 =0		,Mgin2 =0.5		,Oin2 =0.5
number Alin3 =0.5	,Mgin3 =0		,Oin3 =0.5

number clust =0	//this should be 0 (no clustering) unless you wish to acces a specific cluster

image MSAimage :=getFrontImage()
TagGroup MatrixTags = MSA112_GetMatrixTags(MSAimage,0)

string MSALabel = MSA112_Label()
string clusterLabel = MSA112_GetClusterLabel(clust)

number width,height
MatrixTags.MSA112_GetSIWidthHeight(width,height)
number scaleX,originX,scaleY,originY
string unitsX,unitsY
MatrixTags.MSA112_GetCalibration(scaleX,originX,unitsX,"X")
MatrixTags.MSA112_GetCalibration(scaleY,originY,unitsY,"Y")

image Abundancies :=MatrixTags.MSA112_getImagefromTags(clusterLabel+":EndMembering:Abundancies")
number EndmembersNumber,Points
Abundancies.getSize(EndmembersNumber,Points)

image MembersMapCube := realimage("EndMembers abundancies",4,width,height,endMembersNumber)
for(number j=0;j<height;j++)
		{
		MembersMapCube[irow,j,icol] = Abundancies[j*width,0,(j+1)*width,endMembersNumber]
		}

MembersMapCube.ImageSetDimensionCalibration(0,originX,scaleX,unitsX,1)
MembersMapCube.ImageSetDimensionCalibration(1,originY,scaleY,unitsY,1)			
//MembersMapCube.showimage()

image ElementalMapCube :=MembersMapCube.imageClone()
ElementalMapCube =0

image recastOneMap(image MembersMapCube,number ELin1,number ELin2,number ELin3)	
	{
	number width  =MembersMapCube.ImageGetDimensionSize(0)
	number height =MembersMapCube.ImageGetDimensionSize(1)
	
	image ElementMap :=realimage("",4,width,height)

	ElementMap +=MembersMapCube[0,0,0,width,height,1]*ELin1
	ElementMap +=MembersMapCube[0,0,1,width,height,2]*ELin2
	ElementMap +=MembersMapCube[0,0,2,width,height,3]*ELin3

	return ElementMap
	}

ElementalMapCube[0,0,0,width,height,1] =recastOneMap(MembersMapCube,Alin1,Alin2,Alin3)	
ElementalMapCube[0,0,1,width,height,2] =recastOneMap(MembersMapCube,Mgin1,Mgin2,Mgin3)	
ElementalMapCube[0,0,2,width,height,3] =recastOneMap(MembersMapCube,Oin1,Oin2,Oin3)	

ElementalMapCube.showimage()

