
// Script function: Compute reflection angle of bcc and fcc crystal structures in electron diffraction
// In this example, we use the lattice constants of silicon crystals, which can be changed with other crystals.

// 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

//References: https://www.globalsino.com/EM/page2873.html



number MyAngle, EMlambda  // 

TagGroup GlobalSino, EMItems
GlobalSino = DLGCreateDialog( "BCC/FCC reflection angle", EMItems )

TagGroup EMh, EMk, EMl, EMV, EMa

EMItems.DLGAddElement( DLGCreateRealField( "High voltage (kV)", EMV, 200, 12, 3 ) )       

EMItems.DLGAddElement( DLGCreateRealField( "Lattice constant (nm)", EMa, 0.54311959, 8, 3 ) )       

EMItems.DLGAddElement( DLGCreateRealField( "h", EMh, 1, 27, 3 ) )       
EMItems.DLGAddElement( DLGCreateRealField( "k", EMk, 1, 27, 5 ) )       
EMItems.DLGAddElement( DLGCreateRealField( "l", EMl, 1, 27, 8 ) )       
 
if ( !Alloc( UIframe ).Init( GlobalSino ).Pose() ) exit (0)
 
number MyHighVoltage = 1000*(EMV.DLGGetValue())
EMlambda = 1.23 / (sqrt(MyHighVoltage + 0.000001*MyHighVoltage*MyHighVoltage))

number EMLatticeConstant = EMa.DLGGetValue()

number EMhSquare = (EMh.DLGGetValue())*(EMh.DLGGetValue())
number EMkSquare = (EMk.DLGGetValue())*(EMk.DLGGetValue())
number EMlSquare = (EMl.DLGGetValue())*(EMl.DLGGetValue())


MyAngle = 1000*2*asin((sqrt(EMhSquare+EMkSquare+EMlSquare))*(EMlambda/(2*EMLatticeConstant))) // 

result (MyAngle + " mrad\n")

// pop-up window
String GlobalSinoPopupResults = "The reflection angle is \n"
GlobalSinoPopupResults += MyAngle + " mrad\n"
OKDialog (GlobalSinoPopupResults)






