
// Script function: Compute reflection angle of bcc and fcc crystal structures in XRD
// 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





number MyAngle  // 

TagGroup GlobalSino, EMItems
GlobalSino = DLGCreateDialog( "BCC/FCC reflection angle", EMItems )

TagGroup EMh, EMk, EMl, EMa, EMlambda 

EMItems.DLGAddElement( DLGCreateRealField( "Wavelength ¦Ë (A)", EMlambda, 1.5405929, 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 EMLatticeConstant = EMa.DLGGetValue()
number EMWavelength = EMlambda.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))*(EMWavelength/10/(2*EMLatticeConstant)))/17.45

result (MyAngle + " Degree\n")

// pop-up window
String GlobalSinoPopupResults = "The reflection angle is \n"
GlobalSinoPopupResults += MyAngle + " Degree\n"
OKDialog (GlobalSinoPopupResults)






