// Script function: Export an 1D profile to text format, which can be input into spreadsheet (excel).
// Requirement: Open an 1D image as front-most

// 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

documentwindow GlobalSinoExport(image EMoneD)
{
string GlobalSinoProfileName=getname(EMoneD)
number EMScale, EMOrigin, EMxSize, EMySize //
string EMUnits //
EMoneD.imagegetdimensioncalibration(0, EMOrigin,EMScale,EMUnits,1) //

getsize(EMoneD, EMxSize, EMySize) //

documentwindow MyTextWindow //
MyTextWindow=NewScriptWindow("Tabbe of " + GlobalSinoProfileName, 0,100, 10, 100) //

number EMi
for(EMi=0; EMi<EMxSize; EMi++)
{
number EMoneDyValue=getpixel(EMoneD, EMi,0)
number EMoneDxValue=(EMi-EMOrigin)*EMScale
editorwindowaddtext(MyTextWindow,format(EMoneDxValue,"%8.4f")+"\t"+format(EMoneDyValue, "%8.4f")+"\n")
}
return MyTextWindow
}

void main()
 {                             
image GlobalSinoEMImage := getfrontimage()
number EMxSize, EMySize
getsize(GlobalSinoEMImage,EMxSize, EMySize)

if(EMySize!=1)
{
Throw( "Please open an 1D image as front-most!" )
}
documentwindow GlobalSinoExportedProfile=GlobalSinoExport(GlobalSinoEMImage)
windowshow(GlobalSinoExportedProfile)
GlobalSinoExportedProfile.windowsetframeposition(20,20)
windowselect(GlobalSinoExportedProfile)
string GlobalSinoProfileName=windowgettitle(GlobalSinoExportedProfile)
}
 
main()
