
// Script function: Sum the counts of a spectrum.
// Requirement: At least open one EDS or EELS spectrum. 

// Unless named starting with GlobalSino, EM, My, Self, the function commands are defined 
//by Gatan DM, please see at link: http://www.globalsino.com/EM/page2597.html



image GlobalSinoSpectrum

if ( !GetFrontImage( GlobalSinoSpectrum ) )
 Throw( "Please at least open one EDS or EELS spectrum!" )

GlobalSinoSpectrum:=getfrontimage()
number EMxsize, EMysize, EMSum, EMOrigin, EMScale
string EMUnits
getsize(GlobalSinoSpectrum, EMxsize, EMysize)

if(EMysize>1)
{
    Throw( "Please open an EDS or EELS spectrum in front-most!" )
	exit(0)
}

imagegetdimensioncalibration(GlobalSinoSpectrum,0, EMOrigin, EMScale,EMUnits,0)
EMSum=sum(GlobalSinoSpectrum)

result("\nTotal counts of the spectrum are "+EMSum+" counts.\n")
showalert("Total counts of the spectrum are " + EMSum + " counts.", 2)
